Defined cell and formula in VBA

theteacher9999

New Member
Joined
Jun 8, 2020
Messages
12
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi,

Here is part of my code:

VBA Code:
mycell = ActiveCell.AddressLocal(False, False) 'it is O2
Cells(1, Range("A1").End(xlToRight).Column + 1).Offset(1, 0).Activate
Selection.Formula = "=IF(mycell=""Blue"",""yes"",""no"")"

What I get in the selected cell is: #NAME?

When I type the below all is fine but I don't want to enter a specific cell here becasue the intial ActiveCell may vary.
VBA Code:
Selection.Formula = "=IF(O2=""Blue"",""yes"",""no"")"

Do you know how to correct it?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I believe you want

VBA Code:
Selection.Formula = "=IF(" & mycell & "=""Blue"",""yes"",""no"")"

Hope that helps.

Regards,
Ken
 
Upvote 0
Solution

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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