VBA Help. Drag colum to the last row with data

Joined
Dec 17, 2013
Messages
37
Hi,

I import data from a raw cvs file and run formatting macros. However i want a unique number on each row in the A colum which will be used as a primary key in access. I have made the formula to generate a unique number, but i need a macro to drag down the formula to the last populated row everytime it is updated. Could anybody suggest VBA code that will allow me to do this.

Thanks in Advance,

HeyYouYesYouNoNotYouYou

  • :biggrin:
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Code:
Sub test()
Dim LastRow As Long
LastRow = ActiveSheet.UsedRange.Rows.Count
Range(Cells(2, 1), Cells(LastRow, 1)).Formula = "Your formula goes here"
End Sub
 
Upvote 0
Welcome to MrExcel.

One way to do this is, assuming your formula is in StartCell is:

Code:
Sub dragFormula()
Set StartCell = Range("A2")
StartCell.Resize(ActiveSheet.UsedRange.Cells(ActiveSheet.UsedRange.Rows.Count, 1).Row - StartCell.Row + 1, 1).FillDown
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,153
Messages
6,123,325
Members
449,097
Latest member
gameover8

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