2016-04-09 7 views
-1

Ich bin nur ein Anfänger für VBA, aber in MS Excel voran. Deshalb bin ich sehr daran interessiert, VBA zu lernen. ok das ist meine erste Frage hierherauszufinden, Zell-Adresse mit = Blatt Name

Actully muss ich Blatt Excel-Format, wo Dateiname = sheet1 Name ist, und es ist irgendwo in der Spalte „A“ so möchte ich über diese Zelle & löschen Sie alle Zeilen auszuwählen & unten bis es eine leere Zelle/Reihe gibt.

Ich habe viel mit InStr & versucht, Funktion zu finden, aber kein Erfolg. Versuchen Sie auch, Zellenadresse wie B5 zu finden, aber das konnte nicht.

+3

Beitrag, was Sie bisher versucht haben, – newguy

Antwort

0

Willkommen bei StackOverflow. Wie du bereits von newguy erfahren hast, solltest du beim Posten einer Frage auch zeigen, was du bisher probiert hast ... ein Stück Code, Druckbild, etc.

Deine Erklärung war nicht so klar (zumindest für mich)), aber basierend auf dem, was ich verstanden habe, habe ich eine kleine Codebeispiel für Sie gemacht, um Sie zu beginnen. Ich habe den Code in die Funktionsblöcke aufgeteilt, damit Sie besser verstehen, was sie erreichen wollen. Hier

ist der Code:

'the following function will find cell with the specific text 
Private Function FindCell(ws As Worksheet, strToSearch As String, Optional sColumn As String = "A") As Integer 
    Dim iCounter As Integer 

    'as you do not know where exactly it exists, we loop from first cell in the particular row 
    'to the very last celll 
    With ws 
     For iCounter = 1 To .Range("A65000").End(xlUp).Row ' or .UsedRange.Rows.Count, or any other method 
      If .Range(sColumn & iCounter).Value = strToSearch Then 
       'yay, we have found the cell! 
       'pass out the reference 
       FindCell = iCounter 

       'now call exit function as we no longer need to continue searching for the cell (we have already found it!) 
       Exit Function 
      End If 
     Next iCounter 
    End With 

    'in case the cell does not exist, we can return -1 
    FindCell = -1 
End Function 

'the following cell will search the very first cell to the top (starting from specific row), which is blank/empty 
Private Function FindEmptyCell(ws As Worksheet, iStartRow As Integer, Optional sColumn As String = "A") As Integer 
     'This function does the same, as if you have selected specific cell 
     'and then pressed left Ctrl + Up arrow at the same time 
     'Try it! 
     'You can do the same with Right + Left + Bottom arrow as well 
     FindEmptyCell = ws.Range(sColumn & iStartRow).End(xlUp).Row + 1 
End Function 

Private Sub EraseRows() 
    Dim iStartCell As Integer 
    Dim iEndCell As Integer 
    On Error GoTo 0 
    'First let's find the "bottom" cell which is the cell with the specific text you are looking for 
    iEndCell = FindCell(ActiveSheet, "TextIAmLookingFor") 

    'now let's see find the top blank cell (so that we get the range of from - to that you want to erase) 
    iStartCell = FindEmptyCell(ActiveSheet, iEndCell) 

    'now we can delete the rows! 
    'iEndCell-1 because you don't want to erase the cell with your search string, right? 
    ActiveSheet.Rows(CStr(iStartCell) & ":" & CStr(iEndCell - 1)).EntireRow.Delete (xlUp) 
End Sub 
Verwandte Themen