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?
 
Try
Code:
Sub tp()
'
' tp Macro
'
Range("A1").Value = "tp"
Range("A2", Range("F" & Rows.Count).End(xlUp)).FormulaR1C1 = _
   "=IF(iserror(VLOOKUP(RC[5],Sheet1!C,1,FALSE)),""yes"",""no"")"
Range("A7").Select
End Sub
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
But I want the data to be filled in automatically when I run a macro. I'm not sure what alternative option you are suggesting? I mean, I'm using Excel, this is an Excel forum, so therefore I'm using a table.
 
Upvote 0
Try
Code:
Sub tp()
'
' tp Macro
'
Range("A1").Value = "tp"
Range("A2", Range("F" & Rows.Count).End(xlUp)).FormulaR1C1 = _
   "=IF(iserror(VLOOKUP(RC[5],Sheet1!C,1,FALSE)),""yes"",""no"")"
Range("A7").Select
End Sub

This bring up a window asking for me to select a file to update values????
 
Upvote 0
In that case, I suspect that you don't have a sheet called "Sheet1" in that workbook.
 
Upvote 0
Any time your referring to a Table it's best to give us the Table name.
And refer to columns in the Table.

Like enter "Jane" into Table Named Me Column(1)

This would be column (1) of the Table not Column(1) of the sheet.
 
Upvote 0
Ok, small progress ...

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

This is not erroring, but it has changed all the values in columns A to F to yes (even if they are meant to be no). I only want the data changed in column A.
 
Upvote 0
Sorry, I don't understand this talk of tables. It's very confusing. I'm using Excel. It's a very basic sheet, that I just want to cross reference with another sheet. My data starts at A1
 
Upvote 0
Oops, it should be
Code:
Sub tp()
'
' tp Macro
'
Range("A1").Value = "tp"
Range("[COLOR=#ff0000]A2:A[/COLOR]", Range("F" & Rows.Count).End(xlUp)[COLOR=#ff0000].Row[/COLOR]).FormulaR1C1 = _
   "=IF(iserror(VLOOKUP(RC[5],Sheet1!C,1,FALSE)),""yes"",""no"")"
Range("A7").Select
End Sub
 
Upvote 0
Really appreciate your help, but still no joy. Now I get a run time error 1004, range of object global failed with these two rows highlighted when I click debug ...

Range("A2:A", Range("F" & Rows.Count).End(xlUp).Row).FormulaR1C1 = _
"=IF(iserror(VLOOKUP(RC[5],sheet1!C,1,FALSE)),""yes"",""no"")"
 
Upvote 0
Sorry, I don't understand this talk of tables. It's very confusing. I'm using Excel. It's a very basic sheet, that I just want to cross reference with another sheet. My data starts at A1

You said in your original post:
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.

A Table and a sheet are not the same.

A Table is a certain range on a Sheet.
Not sure what version of Excel your using.

But on most never versions even as far back as 2013 you can insert on your sheet a Table.
On Your ribbon you should see Insert Table.

So if you are not using a Table you should say my sheet column A length changes.
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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