How to loop / with below code

Thecraftycarrot

New Member
Joined
Nov 8, 2018
Messages
27
Hi all i have the below code that works perfectly when it is known that there is only one row item that needs to be copied from one sheet to another, then deleted from the orginal source.

However i am struggling to convert the below code into a repeatable with / loop statment that checks, copies, moves, pastes and then deletes multiple rows of applicable data.

Code:
Dim UpdateRow As Long
Dim UpdateCol As Long
Dim ColName As String
Dim S3 As Worksheet
Dim S2 As Worksheet
Dim S1 As Worksheet


Set S3 = Sheets("SHEET3")
Set S2 = Sheets("SHEET2")
Set S1 = Sheets("SHEET1")



        Rowname = S1.Range("E16").Value
        UpdateRow = S2.Range("A3:a1000").Find(Rowname, LookIn:=xlValues).Row
        ColName = "Contract number"
        UpdateCol = S2.Range("A2:AZ2").Find(ColName, LookIn:=xlValues).Column
        S2.Select
        S2.Range(Cells(UpdateRow, UpdateCol), Cells(UpdateRow, UpdateCol).Offset(0, 29).Address).Copy
        
        Rowname = S3.Range("a10000").End(xlUp).Row
        ColName = "Contract line number"
        UpdateCol = S3.Range("A2:AZ2").Find(ColName, LookIn:=xlValues).Column
        S3.Select
        S3.Cells(Rowname, UpdateCol).Paste

any insights would be great.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,214,948
Messages
6,122,420
Members
449,083
Latest member
Ava19

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