Loop to clear, copy, paste

kubabocz

New Member
Joined
Oct 28, 2015
Messages
34
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 ?
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

kubabocz

New Member
Joined
Oct 28, 2015
Messages
34
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.
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,042
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
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:

Watch MrExcel Video

Forum statistics

Threads
1,127,243
Messages
5,623,579
Members
415,981
Latest member
Baltwin

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
Top