VBA code to set Range row number based on cell value

rjheibel

New Member
Joined
Mar 8, 2018
Messages
42
I would like to set the row number in my paste formulas Range based on the value in Cell A3 on a specified worksheet. Specifically in the code below, I would like the value of P5000 to be based on the value in cell A3. Any help would be greatly appreciated.

Sheets("Expected Finish Dates").Select
Range("B4034:P4034").Select
Application.CutCopyMode = False
Selection.Copy
Range("B4035:P5000").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Will A3 hold the number of rows the formulae should be copied to, or the last row number?
 
Upvote 0
I ended up using the following code, which worked....

VBA Code:
Sheets("Expected Finish Dates").Select
    Dim LastRow
    LastRow = Range("A3").Value
 
    Range("B4034:P4034").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("B4035:P" & LastRow).Select
    Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
 
Upvote 0
Solution
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,398
Members
449,155
Latest member
ravioli44

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