D
Dave
Hi,
I hope someone has a little patience with me on this one and can help.
Here goes...
I'm trying to use VBA to insert formulas into a defined range on the
worksheet. I'm doing this so the user cannot fiddle with the formulas
if they open the workbook and disable the macros ie. no formulas will
be visible to them to mess with.
This is what the formula looked like when it was embedded in the
worksheet...
=IF(D17 <>"",VLOOKUP(D17,Food_Prices,2,FALSE),"")
I changed it in my VBA to look like this...
Range("Unit").Formula =
"=IF(ISBLANK(D17),"""",VLOOKUP(D17,Food_Prices,2,FALSE))"
No problem so far - only that it pastes in the same formula into evry
cell in the range ie. they ALL have D17 in. So I set up a loop to try
and change the addresses like this...
For Each unit_cell In Range("Unit")
unit_cell.Select
addr = ActiveCell.Offset(-1).Address
unit_cell.Formula =
"=IF(ISBLANK(VALUE(addr)),"""",VLOOKUP(D17,Food_Prices,2,FALSE))"
Next
Yep, you guessed it - 2 hours later and all I've ended up with is this
in every cell in the range...
=IF(ISBLANK(VALUE(addr)),"",VLOOKUP(D17,Food_Prices,2,FALSE))
I'm now running out of ideas - can someone please show me how to
change the actual cell address depending on where the actual address
of my named range is ?
I hope that made sense.
Many thanks,
Dave
I hope someone has a little patience with me on this one and can help.
Here goes...
I'm trying to use VBA to insert formulas into a defined range on the
worksheet. I'm doing this so the user cannot fiddle with the formulas
if they open the workbook and disable the macros ie. no formulas will
be visible to them to mess with.
This is what the formula looked like when it was embedded in the
worksheet...
=IF(D17 <>"",VLOOKUP(D17,Food_Prices,2,FALSE),"")
I changed it in my VBA to look like this...
Range("Unit").Formula =
"=IF(ISBLANK(D17),"""",VLOOKUP(D17,Food_Prices,2,FALSE))"
No problem so far - only that it pastes in the same formula into evry
cell in the range ie. they ALL have D17 in. So I set up a loop to try
and change the addresses like this...
For Each unit_cell In Range("Unit")
unit_cell.Select
addr = ActiveCell.Offset(-1).Address
unit_cell.Formula =
"=IF(ISBLANK(VALUE(addr)),"""",VLOOKUP(D17,Food_Prices,2,FALSE))"
Next
Yep, you guessed it - 2 hours later and all I've ended up with is this
in every cell in the range...
=IF(ISBLANK(VALUE(addr)),"",VLOOKUP(D17,Food_Prices,2,FALSE))
I'm now running out of ideas - can someone please show me how to
change the actual cell address depending on where the actual address
of my named range is ?
I hope that made sense.
Many thanks,
Dave