Can I amend a macro to repeat with different rows

ghrek

Active Member
Joined
Jul 29, 2005
Messages
426
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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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,214,376
Messages
6,119,180
Members
448,871
Latest member
hengshankouniuniu

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