Macro ActiveSheet.Formula Object doesn't support this property or method error

starheartbeam

New Member
Joined
Aug 8, 2018
Messages
18
I am trying to do the following:

ActiveSheet.Formula = "=IF(TEXT(E2,""YYYYMM"")< text(m2,""yyyymm""),b2&""-""&c2&""-""&d2&""-""&""01-""&(text(m2,""mmm""))&""-""&(text(m2,""yy"")),b2&""-""&c2&""-""&d2&""-""&e2)"



This works when I put it in an excel formula but when I put it in my macro I get "Object doesn't support this property or method" error and I do not know what I need to do to get this to work? Any help would be very helpful.
 
Last edited by a moderator:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
You need to provide the range also. Otherwise, it does not know where on the Active Sheet you want the formula, i.e.
Code:
[COLOR=#333333]ActiveSheet.[/COLOR][COLOR=#ff0000]Range("A2")[/COLOR][COLOR=#333333].Formula = "=IF(TEXT(E2,""YYYYMM"")[/COLOR]<text(m2,""yyyymm""),b2&""-""&c2&""-""&d2&""-""&""01-""&(text(m2,""mmm""))&""-""&(text(m2,""yy"")),b2&""-""&c2&""-""&d2&""-""&e2)"
 </text(m2,""yyyymm""),b2&""-""&c2&""-""&d2&""-""&""01-""&(text(m2,""mmm""))&""-""&(text(m2,""yy"")),b2&""-""&c2&""-""&d2&""-""&e2)"
 
Upvote 0
It did not let me post my whole code. Here it is:

ActiveSheet.Formula = "=IF(FORMAT(E2,""YYYYMM"")
<
TEXT(M2,""YYYYMM""),B2&""-""&C2&""-""&D2&""-""&""01-""&
(TEXT(M2,""MMM""))&""-""&(TEXT(M2,""YY"")),B2&""-""&C2&""-""&D2&""-""&E2)"
 
Last edited:
Upvote 0
The forum interface strongly prefers spaces before and after less-than symbols.

(A+5) < (B+1) rather than (A+5)<(B+1)
 
Upvote 0
You are still missing the range part, as I mentioned in my initial reply.
 
Upvote 0
The spaces are for this forum, they are not needed for Excel VBA.
Did you add the range object that Joe4 is talking about?
 
Upvote 0
Things can get tricky when you are trying to add in a formula that has literal quote marks, as those are also used for Text delimiters in VBA. If you do not do it correctly, VBA cannot tell if you want literal quotes marks, or you are just denoting text.

I find that the easiest thing to do in these situations is to turn on your Macro Recorder, and enter one of these formulas on your spreadsheet. Then stop the Macro Recorder and view your recorded code. Thois will show you EXACTLY how the formula needs to look in VBA. So you can just copy and paste that recorded formula into your VBA code.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,861
Messages
6,121,971
Members
449,059
Latest member
oculus

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