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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,214,965
Messages
6,122,495
Members
449,088
Latest member
Melvetica

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