Loop to clear, copy, paste

kubabocz

New Member
Joined
Oct 28, 2015
Messages
36
Hi all,

I have a question regarding VBA I need to use.

Can you please help.

The macro needs to do the follwing:
1. Go to sheet 1
2. Clear cells A2 to Z2
3. Go sheet 2
4. Copy cells A2 to Z2
5. Go to sheet 1
6. Paste the cells to the range A2 to Z2
7. Loop throguh points 1 to 6 to the last row in the sheet 2

Of course it will have some more things to do after point 6 but I can manage it myself, anybodey can help ?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Not at the moment. ..i dont have a computer. ...someone else may help....but you will need to provide more information on save type and location
Location can be fixed or choosen each time, both options are ok

Would you be able to try later, I've been fighting with mutliple things found on the internet and can not make it work.
 
Upvote 0
Just passing through to check posts....gone for the day, but you say in a prvious thread..."Go back to previous file"....Is there more than one file ???
You also mentioned you were OK with steps 1 to 6 and could do the rest yourself, consider this code and you can insert the saving requirements as you want.
Rich (BB code):
Sub MM1()
Dim lr1 As Long, lr2 As Long, ws1 As Worksheet, ws2 As Worksheet
Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
lr1 = ws1.Cells(Rows.Count, "A").End(xlUp).Row
lr2 = ws2.Cells(Rows.Count, "A").End(xlUp).Row
ws1.Range("A2:Z" & lr1).Clear
With ws2
For r = 2 To lr2
    .Range("A" & r & ":Z" & r).Copy ws1.Cells(Rows.Count, "A").End(xlUp).Row
    'The saving code goes here
    ws1.Range("A2:Z" & lr1).Clear
    MsgBox "File saved"
Next r
End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,425
Members
448,961
Latest member
nzskater

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