Cell Referencing with a macro

mchong

New Member
Joined
Sep 19, 2008
Messages
25
Hi,

I've got a macro that needs some tweaking. Because the raw data report doesn't have a fixed number of columns, I am having trouble with cell referencing. My code below doesn't work because the cell "BX9" may not always be the correct cell to reference. Can someone tell me how I can get the macro to reference the 1st cell under the header "CODE" instead?


ActiveCell.FormulaR1C1 = "CODE"
Range("BX9").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-3]=""OCF"",""FREIGHT"",IF(RC[-3]=""SFB"",""FREIGHT"",IF(RC[-3]=""SFC"",""FREIGHT"",IF(RC[-3]=""SWE"",""FREIGHT"",IF(RC[-3]=""BAF"",""BAF"","""")))))"


Thanks in advance.

Marco
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Would this be what you're after, or is there more to it?

with activecell
.FormulaR1C1 = "CODE"
offset(1,0).FormulaR1C1 = _
"=IF(RC[-3]=""OCF"",""FREIGHT"",IF(RC[-3]=""SFB"",""FREIGHT"",IF(RC[-3]=""SFC"",""FREIGHT"",IF(RC[-3]=""SWE"",""FREIGHT"",IF(RC[-3]=""BAF"",""BAF"","""")))))"
end with
 
Upvote 0
Hi excelR8R,

Tried to copy your code below into my macro but what I got when running it was "Compile Errror: sub of function not defined". Here's my code, can you tell me what I got wrong?

Range("B13Table[[#Headers],[Charge Currency]]").Select
ActiveCell.Offset(1, 0).EntireColumn.Insert
Range("B13Table[[#Headers],[Column1]]").Select
With ActiveCell
.FormulaR1C1 = "CODE"
Offset(1, 0).FormulaR1C1 = _
"=IF(RC[-3]=""OCF"",""FREIGHT"",IF(RC[-3]=""SFB"",""FREIGHT"",IF(RC[-3]=""SFC"",""FREIGHT"",IF(RC[-3]=""SWE"",""FREIGHT"",IF(RC[-3]=""BAF"",""BAF"","""")))))"
End With

Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,638
Messages
6,120,674
Members
448,977
Latest member
moonlight6

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