VBA loop trough until cell is blank

DMO123

Board Regular
Joined
Aug 16, 2018
Messages
99
Hi All, i have the below code at the moment it just runs on cell Z1 but i want it to move down column Z fetching the data until the cells are blank so the code would run complete Z1 then loop round dropping to Z2 etc. how do i add the loop in?

Code:
Option Explicit

Sub Find_Data()


Dim casenumber As String
Dim finalrow As Integer
Dim i As Integer


Sheets("Data").Range("AD2:AV400").ClearContents


casenumber = Sheets("Data").Range("Z1").Value
finalrow = Sheets("Data").Range("A10000").End(xlUp).Row


For i = 2 To finalrow
    If Cells(i, 1) = casenumber Then
        Range(Cells(i, 1), Cells(i, 19)).Copy
        Range("AD1000").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats
        End If


Next i


Range("Z:Z").Select


    casenumber = casenumber + 1
Loop


End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
How about
Code:
Sub Find_Data()
   Dim CaseNumber As Range
   Dim FinalRow As Long, i As Long
   Dim Mch As Variant
   
   With Sheets("Data")
      .Range("AD2:AV400").ClearContents
      Set CaseNumber = .Range("Z1", .Range("Z" & Rows.Count).End(xlUp))
      FinalRow = .Range("A" & Rows.Count).End(xlUp).Row
      For i = 2 To FinalRow
         Mch = Application.Match(.Cells(i, 1).Value, CaseNumber, 0)
         If Not IsError(Mch) Then
            .Cells(i, 1).Resize(, 19).Copy
            .Range("AD" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats
         End If
      Next i
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,894
Messages
6,122,124
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top