LionelHutz
New Member
- Joined
- Apr 1, 2015
- Messages
- 40
Hi,
So I have a macro code that looks like this:
Sub DragDown123()
'
' DragDown123 Macro
'
'
Sheets("Sheet2").Select
Range("B2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],Sheet1!C1:C2,2,FALSE)"
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:B5")
Range("B2:B4").Select
Range("A1").Select
ActiveCell.FormulaR1C1 = "Name"
Range("A2").Select
Sheets("Sheet1").Select
End Sub
So this simple macro is apart of a bigger macro that does some stuff and pull a formula down. THe issue is the formula only pulls down to row 5. So if I have data in a6 and on the formula does not drag that far down. For the highlighted green part of my code, is there a formula I can use instead that would auto detect how many rows down column A goes and then drag it down?
EDIT: The above sort of reads funny to me so I will try again...
Is there a way I can get the autofill to auto detect how far it needs to be dragged down based on how many rows in column A have data?
So I have a macro code that looks like this:
Sub DragDown123()
'
' DragDown123 Macro
'
'
Sheets("Sheet2").Select
Range("B2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],Sheet1!C1:C2,2,FALSE)"
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:B5")
Range("B2:B4").Select
Range("A1").Select
ActiveCell.FormulaR1C1 = "Name"
Range("A2").Select
Sheets("Sheet1").Select
End Sub
So this simple macro is apart of a bigger macro that does some stuff and pull a formula down. THe issue is the formula only pulls down to row 5. So if I have data in a6 and on the formula does not drag that far down. For the highlighted green part of my code, is there a formula I can use instead that would auto detect how many rows down column A goes and then drag it down?
EDIT: The above sort of reads funny to me so I will try again...
Is there a way I can get the autofill to auto detect how far it needs to be dragged down based on how many rows in column A have data?
Last edited: