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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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