Simple looping macro help

ma0ffst08

Board Regular
Joined
Apr 22, 2008
Messages
128
Office Version
  1. 2019
Platform
  1. Windows
Hello everyone,

I'm sure this will be really easy for someone, but I've been stuck for ages, so any help would be appreciated please.

I have a table with over 2,000 rows of data.

I would like a macro that starts by copying data from C4:V4 and pastes it as values into C1:V1.
Then it would copy the results from W1:Z1 and paste it as values into W4:Z4.

Then it would move down and copy data from C5:V5 and paste it as values into C1:V1.
Then it would copy the results from W1:Z1 and paste it as values into W5:Z5.

And so on, so the last row (for example row 2000), it would copy data from C2000:V2000 and paste it as values into C1:V1.
Then it would copy the results from W1:Z1 and paste it as values into W2000:Z2000.

But the number of rows might change, so it needs to be able to loop for as many rows as there is data. Column C would always hold data (until the whole row is blank).

Thank you so much!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Give this a try.

VBA Code:
Sub DoStuff()
Dim lr As Long
Dim r As Long
Dim Crng As Range
Dim Wrng As Range

Set Crng = Range("C1:V1")
Set Wrng = Range("W1:Z1")

lr = Cells(Rows.Count, "C").End(xlUp).Row
Application.ScreenUpdating = False

    For r = 4 To lr
        Crng.Value = Range("C" & r & ":V" & r).Value
        Range("W" & r & ":Z" & r).Value = Wrng.Value
    Next r
    
Application.ScreenUpdating = True
End Sub
 
Upvote 0
It sounds like you are doing a calculation on the sheet, then saving the values on another row. It might make more sense to just do the calculations in VBA, which would be faster than all of the copy and paste. What are the formulas in W1:Z1?
 
Upvote 0
Give this a try.

VBA Code:
Sub DoStuff()
Dim lr As Long
Dim r As Long
Dim Crng As Range
Dim Wrng As Range

Set Crng = Range("C1:V1")
Set Wrng = Range("W1:Z1")

lr = Cells(Rows.Count, "C").End(xlUp).Row
Application.ScreenUpdating = False

    For r = 4 To lr
        Crng.Value = Range("C" & r & ":V" & r).Value
        Range("W" & r & ":Z" & r).Value = Wrng.Value
    Next r
   
Application.ScreenUpdating = True
End Sub
Thank you so much
 
Upvote 0
It sounds like you are doing a calculation on the sheet, then saving the values on another row. It might make more sense to just do the calculations in VBA, which would be faster than all of the copy and paste. What are the formulas in W1:Z1?
Hi, C1:V1 link to other sheets with various other calculations, so it's just the output from many calcs which come back to W1:Z1. It would be too difficult to do formulas in W1:Z1 in this instance
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

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