Applying a formula down a column, only as far as needed

sobeitjedi

Board Regular
Joined
Mar 13, 2006
Messages
235
Office Version
  1. 365
Hi.

My table length will vary week to week. I want to put data in column A, only if there is data on the same row in column F.

My macro at the moment is...

Range("A1").Select
ActiveCell.FormulaR1C1 = _
"=IF(iserror(VLOOKUP(RC[5],Sheet1!C,1,FALSE)),""yes"",""no"")"

Columns("A:A").Select
Selection.FillDown
Range("A1").Select
ActiveCell.FormulaR1C1 = "tp"
Range("A7").Select


But this is populating the data in the whole of column A, how do I fix?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try
Code:
Range("A1", Range("F" & Rows.Count).End(xlUp)).FormulaR1C1 = _
   "=IF(iserror(VLOOKUP(RC[5],Sheet1!C,1,FALSE)),""yes"",""no"")"
 
Upvote 0
you can create a dynamic range by using a variable to define your last row with data.
Code:
Dim lr As Long
lr = ActiveSheet.Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
Range("A1"),FormulaR1C1 = "=IF(iserror(VLOOKUP(RC[5],Sheet1!C,1,FALSE)),""yes"",""no"")"
Range("A1:A" & lr).Filldown
 
Last edited:
Upvote 0
Assuming you want the value "tp

Put in all cells in column A if there are values in column F

Try this:
Code:
Sub Fill_Down()
'Modified 10/10/2018 8:38 AM  EDT
Application.ScreenUpdating = False
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "F").End(xlUp).Row
Cells(1, 1).Resize(Lastrow).Value = "tp"
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Are you actually using a table?

If you were then the formula would get copied down to the last row of data automatically.
 
Upvote 0
Yes, I'm using a table. Perhaps I need the code putting in my marco from my original post. Maybe I'm putting it in the wrong place?
 
Upvote 0
Ok, so this is the modified macro ...

Sub tp()
'
' tp Macro
'
Range("A1").Select
ActiveCell.FormulaR1C1 = _
Range("A1", Range("F" & Rows.Count).End(xlUp)).FormulaR1C1 = _
"=IF(iserror(VLOOKUP(RC[5],Sheet1!C,1,FALSE)),""yes"",""no"")"

Columns("A:A").Select
Selection.FillDown
Range("A1").Select
ActiveCell.FormulaR1C1 = "tp"
Range("A7").Select
End Sub



And I get error 13 type mismatch. When I go to debug, these lines are highlighted ...

ActiveCell.FormulaR1C1 = _
Range("A1", Range("F" & Rows.Count).End(xlUp)).FormulaR1C1 = _
"=IF(iserror(VLOOKUP(RC[5],Sheet1!C,1,FALSE)),""yes"",""no"")"
 
Upvote 0
If you are using a table you shouldn't need code to copy down the formula.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,217
Members
452,619
Latest member
Shiv1198

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