简体   繁体   中英

EXCEL VBA to select ROWS if Cell A5 contains specific text - caveats

I receive an excel file daily. I am trying to select all ROWS if cells from A5 to the end of the dynamic data contains a string "TURNER 232"

  • Cells A1 to A3 are blank
  • Cells A4 are the column headings
  • Cells A5 to the dynamic end of the sheet always contain "TURNER 232"

I have been copying various examples of code from this website to no avail.

Would appreciate any assistance if possible.

例子

Many thanks Matt

Code used

Sub CustomSelect()
    Dim i As Long: i = 2
    Do While Range("H" & i).Value = "TURNER 232"
        i = i + 1
    Loop
    Range("A5:H" & i - 1).EntireRow.Select
End Sub

Scott,

I used the below which did the trick.

Thanks mate.1st ever soiree into VBA

Sub CustomSelect()
     Dim i As Long: i = 5
     Do While Range("A" & i).Value = "TURNER 232"
        i = i + 1
     Loop
     Range("A5:A" & i - 1).EntireRow.Select
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM