Can I amend a macro to repeat with different rows

ghrek

Active Member
Joined
Jul 29, 2005
Messages
427
Hi

I have this macro that moves data from column G when it contains specific requirements. What im trying to do is to repeat it so if column H contains the specific data then I need data from columns H & I into column BB and then if column I contains the data I need the data from I & J moving into BB and so on until I get to column Z.

Can this be done?


Dim ws As Worksheet
Dim lr As Long, i As Long

Application.ScreenUpdating = False

Set ws = Worksheets("Sheet 1") 'Data Sheet
lr = ws.Cells(Rows.Count, "G").End(xlUp).Row

For i = 1 To lr
If UCase(ws.Cells(i, "G").Value) = "Sale Number (SDCI+)" Then
ws.Range("G" & i & "H" & i).Cut ws.Range("BB" & i)
End If
Next i
Application.ScreenUpdating = True
'
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try this:
Code:
Sub MyCutAndPaste()

    Dim ws As Worksheet
    Dim lr As Long, i As Long
    Dim c As Long

    Application.ScreenUpdating = False

    Set ws = Worksheets("Sheet 1") 'Data Sheet
    
'   Specify columns to loop through, numerical (G=7, H=8, I=9,...)
    For c = 7 To 9
        lr = ws.Cells(Rows.Count, c).End(xlUp).Row

'       Loop through all rows in the column
        For i = 1 To lr
            If UCase(ws.Cells(i, c).Value) = "Sale Number (SDCI+)" Then
                ws.Range(Cells(i, c), Cells(i, c + 1)).Cut ws.Range("BB" & i)
            End If
        Next i
    Next c
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,636
Members
452,662
Latest member
Aman1997

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