2016-02-02 7 views
5

निम्न स्क्रिप्ट छोटे डेटा सेट (30k पंक्तियों से कम या उससे कम) पर काम करती है, लेकिन चयनित श्रेणी में प्रत्येक सेल के लिए "#VALUE" त्रुटियों का परिणाम होता है जब सीमा उस से बड़ी होती है।वीबीए और एक्सेल: मेरे डेटा स्क्रिप्ट का परिणाम #VALUE में बड़े डेटा सेट पर क्यों होता है?

Dim FirstCell As Range, LastCell As Range, MyRange As Range 

Set LastCell = Cells(Cells.Find(What:="*", SearchOrder:=xlRows, _ 
     SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _ 
     Cells.Find(What:="*", SearchOrder:=xlByColumns, _ 
     SearchDirection:=xlPrevious, LookIn:=xlValues).Column) 

Set FirstCell = Cells(Cells.Find(What:="*", After:=LastCell, SearchOrder:=xlRows, _ 
     SearchDirection:=xlNext, LookIn:=xlValues).Row, _ 
     Cells.Find(What:="*", After:=LastCell, SearchOrder:=xlByColumns, _ 
     SearchDirection:=xlNext, LookIn:=xlValues).Column) 

Set MyRange = Range(FirstCell, LastCell) 
     MyRange.Select 
     If MyRange Is Nothing Then Exit Sub 
     Application.ScreenUpdating = False 
     Application.Calculation = xlCalculationManual 
    With Selection 
     .Value = Evaluate("if(row(" & .Address & "),clean(trim(" & .Address & ")))") 
    End With 

    Application.ScreenUpdating = True 
    Application.Calculation = xlCalculationAutomatic 
    MsgBox "Finished trimming " & vbCrLf & "excess spaces", 64 

VBA TRIM Error

+0

इस कोड के साथ आप कितने सेल बदल रहे हैं? मैंने अभी इसे ~ 1.7 मिलियन सेल्स पर परीक्षण किया है और मुझे अपने अभ्यास दस्तावेज़ पर – TMH8885

+0

8,106,860 कोशिकाओं में कोई त्रुटि नहीं मिली है। यह 161,363 पंक्तियां है। –

+0

ऐसा लगता है कि यह लगभग 70k पंक्तियों तक काम करता है। उस से बहुत अधिक, यह चयनित श्रेणी में प्रत्येक सेल का मान #VALUE पर सेट करता है। –

उत्तर

1

मैं सेट

Dim FirstCell As Range, LastCell As Range, MyRange As Range 
Dim DataRange() As Variant 
Dim lRows As Long 
Dim lCols As Long 
Dim i As Long, j As Long 
Dim value As String 

Set LastCell = Cells(Cells.Find(What:="*", SearchOrder:=xlRows, _ 
     SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _ 
     Cells.Find(What:="*", SearchOrder:=xlByColumns, _ 
     SearchDirection:=xlPrevious, LookIn:=xlValues).Column) 

Set FirstCell = Cells(Cells.Find(What:="*", After:=LastCell, SearchOrder:=xlRows, _ 
     SearchDirection:=xlNext, LookIn:=xlValues).Row, _ 
     Cells.Find(What:="*", After:=LastCell, SearchOrder:=xlByColumns, _ 
     SearchDirection:=xlNext, LookIn:=xlValues).Column) 

Set MyRange = Range(FirstCell, LastCell) 
    MyRange.Select 
    If MyRange Is Nothing Then Exit Sub 
    Application.ScreenUpdating = False 
    Application.Calculation = xlCalculationManual 
    lRows = MyRange.Rows.Count 
    lCols = MyRange.Columns.Count 
    ReDim DataRange(1 To lRows, 1 To lCols) 
    DataRange = MyRange.value 
    For j = 1 To lCols 
    For i = 1 To lRows 
     DataRange(i, j) = Trim(DataRange(i, j)) 
    Next i 
    Next j 

    MyRange.value = DataRange 

Application.ScreenUpdating = True 
Application.Calculation = xlCalculationAutomatic 
MsgBox "Finished trimming " & vbCrLf & "excess spaces", 64 

संदर्भ के लिए जिन्हें आप नीचे देख बड़े डेटा के लिए इस मुद्दे को काबू आपकी समस्या को दोहराने के लिए, और एक प्रकार सरणी का उपयोग कर में कामयाब रहे, मैं इस लेख में प्रयोग किया जाता मदद करने के लिए उत्तर के साथ आओ: https://blogs.office.com/2008/10/03/what-is-the-fastest-way-to-scan-a-large-range-in-excel/

+0

भविष्य में लिंक टूटा जा सकता है। कृपया अपनी पोस्ट में प्रश्न का उत्तर देने के लिए आवश्यक जानकारी की प्रतिलिपि बनाएं। केवल संदर्भ के रूप में लिंक का उपयोग करें। – eirikdaude

+0

मैंने इसे और अधिक स्पष्ट करने के लिए उत्तर अपडेट किया है कि लिंक केवल संदर्भ के लिए था, उत्तर ऊपर शामिल है – TrtlBoy

संबंधित मुद्दे