VBA copy down using relative references

SueKi

New Member
Joined
Feb 15, 2022
Messages
44
Office Version
  1. 365
Platform
  1. Windows
Hi, I have a few different items that I typically add to an assortment of reports. I create a macro that inserts a column where I have my cursor, name the column, then put the formula I need in the top cell. My macro ends there I double click to copy it down. It works, but I I recently learned to do the copy down part if I know what column I'm in, it would be great to add that last step to my macros, but I don't know how to reference it right. Can someone help me to correct this so it works? Column A has no blank rows, I need to put the formula in whatever column my macro is at when it reaches this bit....

LastRow = Range("a" & Rows.Count).End(xlUp).Row

Range(ActiveCell.Column() & LastRow).Formula = "=IF(RC[-1]<TODAY(),""PD"",ISOWEEKNUM(RC[-1]))"

Thanks in advance!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Welcome to the Board!

Try something like this:
VBA Code:
Dim c as Long
Dim LastRow as Long

'Get current column
c = ActiveCell.Column

'Find last row in column A
LastRow = Range("A" & Rows.Count).End(xlUp).Row

'Populate formula from row 1 to last row
Range(Cells(1, c), Cells(LastRow, c)).FormulaR1C1 = "=IF(RC[-1]<TODAY(),""PD"",ISOWEEKNUM(RC[-1]))"
 
Upvote 0
Solution
Works like a charm! Thank you so much! You have no idea how often I have to insert little things to consolidate data like this one, or identify customer groups. I'll use this constantly!
 
Upvote 0
Welcome to the Board!

Try something like this:
VBA Code:
Dim c as Long
Dim LastRow as Long

'Get current column
c = ActiveCell.Column

'Find last row in column A
LastRow = Range("A" & Rows.Count).End(xlUp).Row

'Populate formula from row 1 to last row
Range(Cells(1, c), Cells(LastRow, c)).FormulaR1C1 = "=IF(RC[-1]<TODAY(),""PD"",ISOWEEKNUM(RC[-1]))"
Oh, and I'm so excited to find such an active board, it seems like a great resource.
 
Upvote 0
You are welcome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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