2010-11-03 14 views
5

में एक्सेल वर्कशीट के नीचे खोजें मैं वर्कशीट के निचले हिस्से में चयन करना चाहता हूं, लेकिन जो भी उपयोग/संग्रहीत किया गया है उसके नीचे नहीं। मेरे पास 10,000 पंक्तियां हो सकती हैं, लेकिन मेरे पास निश्चित रूप से 65,536 नहीं है। मैं समय से पहले कितनी पंक्तियों को नहीं जानूंगा।वीबीए

एक्सेल में (हाल के संस्करणों में, वैसे भी; एक्सेल 97 इतना दयालु नहीं था) आप अंतिम पंक्ति और कॉलम पर जाने के लिए Ctrl + End दबा सकते हैं। मुझे एक ही कार्यक्षमता चाहिए।

उत्तर

3

कुछ का उपयोग करने के लिए सुरक्षित होगा सबसे आसान तरीका नीचे शुरू करना है और आखिरी पंक्ति को खोजने के लिए काम करना है जिसमें कुछ शामिल है:
रेंज ("a65536")। अंत (xlup) .row

+0

जब तक शीट 65536 वें पंक्ति से भरी न हो .. जो 99% मामलों में, मामला नहीं है। मैं यह सीमा ("ए 1) .end (xlDown) या इसी तरह के –

+3

पर करूँगा यदि आप नीचे खाली सेल पर एक्सएल बंद हो जाते हैं: अक्सर खाली सेल के बाद अधिक डेटा होता है। यदि आप नीचे से शुरू करते हैं और ऊपर जाते हैं आपको यह समस्या नहीं है। –

2

वह प्राथमिक है:

Selection.End(xlDown).Select 

(इस ctrl + अंत दबाने, जबकि एक मैक्रो को रिकॉर्ड करके पता चला।)

+0

आपको सावधान रहना होगा, अगर आपके पास खाली पंक्ति है तो कभी-कभी यह केवल इसका चयन करेगा और बाद में सब कुछ अनदेखा कर देगा। मैं आमतौर पर वहां पहुंचने वाली पंक्ति को पकड़ लेता हूं, अगले 2-3 कक्षों की जांच करता हूं और यदि कोई मिलान नहीं मिला, तो अन्यथा मुझे उस क्षेत्र और लूप का 'अंत' मिल जाएगा जब तक कि मेरे पास 2 या 3 लगातार रिक्त स्थान न हों। – pinkfloydx33

2
Public Sub Blank_Row_Remover() ' Start of Macro Code 

'Deletes the Entire Row within the Selection if _ 
Some of the Cells Within the Selection Contain No Data. 

Dim Start_Cell, End_Cell, Data_Info, End_Column, This_Column As Variant 

Application.ScreenUpdating = False 
Application.StatusBar = "Please Stand By, ('Removing Blank Rows...' ~ Macro In Progress)..." 

    Call Data_Info_Selection(Start_Cell, End_Cell, Data_Info, End_Column, This_Column) ' Direct Method 

    For Each Cell In Selection 
     Cell.Formula = Replace(Cell.Formula, Cell.Formula, Trim(Cell.Formula)) {Rids Extra Spaces} 
     'If InStr(Cell.Value, "Labels:") Then Cell.EntireRow.Clear 'Searching for a Particular String to Remove a Row 
     'If InStr(Cell.Value, " ") Then Cell.EntireRow.Clear 'Searching for another Particular String to Remove a Row {Like 4 Spaces in a Cell that Keeps it from Reading as a Blank} 
    Next 
     On Error Resume Next 
      Selection.SpecialCells(xlBlanks).EntireRow.Delete 
     On Error GoTo 0 

    'Call Data_Info_Selection(Start_Cell, End_Cell, Data_Info, End_Column, This_Column) ' Direct Method 

Application.ScreenUpdating = True 
End Sub 
Public Function Data_Info_Selection(ByRef Start_Cell, End_Cell, Data_Info, End_Column, This_Column As Variant) 

Application.ScreenUpdating = False 
Application.StatusBar = "Please Stand By, ('Selecting Partial Columns' ~ Macro In Progress)..." 

Start_Cell = ActiveCell.Address 
Start_Cell_Text = Range(Start_Cell).Text 

Orginal_Start_Cell = Range(Start_Cell).Address 

If Start_Cell_Text = "" Then 
    Dim Cells As Range 
     For Each Cell In Selection.Cells 
      If Cell = "" Then 
       Start_Cell = Cell.Address 
      Else 
       Start_Cell = Cell.Address 
       Exit For 
      End If 
     Next 
End If 

    This_Column = Mid(Start_Cell, 2, 1) 'ColumnNum = ActiveCell.Column 
     If Range(Start_Cell).Text = "" Then 
      End_Column = This_Column & ActiveCell.Row 
      End_Cell = Range(End_Column).Address 
     Else 
      End_Column = This_Column + "65536" 
      End_Cell = Range(End_Column).End(xlUp).Address 
      Start_Cell = Range(Orginal_Start_Cell).Address 
     End If 

    Data_Info = Range(Start_Cell, End_Cell).Address 
    Range(Data_Info).Select 

End Function 
Public Sub Select_Partial_Data_Start_Cell() ' (This Seems to Work and is Cleaner and Simplier) 

Application.ScreenUpdating = False 
Application.StatusBar = "Please Stand By, ('Selecting Partial Data' ~ Macro In Progress)..." 

Dim myLastRow As Long 
Dim myLastColumn As Long 

    Start_Cell = ActiveCell.Address 
    On Error Resume Next 
     myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row 
     myLastColumn = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column 
     myLast_Cell = Cells(myLastRow, myLastColumn).Address 
    myRange = Start_Cell & ":" & myLast_Cell 
    'If InStr(1, myLast_Cell, "104876", 1) Then myLast_Cell = "$F$1105" 

Range(myRange).Select 
Application.ScreenUpdating = True 

End Sub' End of Macro Code 
0

मैं का उपयोग किया है यह पहले से

'This finds the last row in thr worksheet 
LR = Cells(Rows.Count, 18).End(xlUp).Row 
Range(Cells(LR, 1), Cells(LR, 35)).Select 
0

इस समारोह अधिकतम पंक्ति और अधिकतम स्तंभ का कोई रिटर्न कुछ सामग्री के साथ वर्कशीट में। शायद यह sbdy के लिए उपयोगी होगा। बेशक यह बहुत धीमा है, लेकिन आम तौर पर हमें सभी पंक्तियों और स्तंभों की जांच करने की आवश्यकता नहीं है, इसलिए किसी को लूप को समायोजित करना होगा।

Public Function content_area(shName As String) As Variant 
Dim res(1 To 2) As Integer 
Dim ark As Worksheet 

Set ark = ThisWorkbook.Sheets(shName) 
nCol = 0 
nRow = 0 

For i = 1 To ark.Columns.Count 
    temp = ark.Cells(ark.Cells(1, i).EntireColumn.Rows.Count, i).End(xlUp).Row 
    If temp > nCol Then nCol = temp 
Next 
For i = 1 To ark.Rows.Count 
    temp = ark.Cells(i, ark.Cells(i, 1).EntireRow.Columns.Count).End(xlToLeft).Column 
    If temp > nRow Then nRow = temp 
Next 

res(1) = nCol 
res(2) = nRow 

content_area = res 
End Function