Works as formula but doesn't work as VBA

Pete2211

New Member
Joined
Mar 26, 2019
Messages
6
Hi.
I have the below code which isn't working in VBA.
The formula works perfectly as a formula placed manually in the cell but doesn't work as part of the macro.
It seems to be the "" at the end of the formula which is confusing it. Please can somebody help?

Code:
    Sub FillEXTEND()
Sheets("OVERDUE").Select
    range("M1").Select
Dim LastRowColumnJ As Long
LastRowColumnJ = Cells(Rows.Count, 1).End(xlUp).Row
range("M2:M" & LastRowColumnJ).Formula = "=IF(and(J2<=TODAY(),L2<=Today(),ROUND((TODAY()-L2)/7,1),[U][B][SIZE=4][I]""[/I][/SIZE][/B][/U])"
End Sub

As you can see from the coding, I'm an absolute beginner at this so please bare with me.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi & welcome to MrExcel
You need to double up on the quotes so instead of "" you need """"
 
Last edited:
Upvote 0
Hi Fluff.

That doesn't work either but thank you for trying for me.
By the way, my nickname is Fluff and I live just 20 miles up the M4 from your location
 
Upvote 0
Looks like you're missing a closing bracket as well.
 
Upvote 0
Once again, many thanks. I really appreciate you taking time out of your busy day to look at this.
I spotted the missing closing bracket at the end of the AND statement but can't see any others yet it still isn't working
Unfortunately, the error code is the ambiguous '1004' so that doesn't help either of us with any clues
 
Upvote 0
What is the message that goes with the code?
 
Upvote 0
Also can you post the amended formula and your variable is LastRowColumnJ, but you are looking in col A for the last row.
 
Upvote 0
Code:
...Formula = "=IF(AND(J2 <= TODAY(), L2 <= TODAY(), ROUND((TODAY() - L2) / 7, 1)), """")"
 
Upvote 0
Hi
The error message is 'Application-defined or Object-defined error

Code:
    Sub FillEXTEND()
Sheets("OVERDUE").Select
    range("M1").Select
Dim LastRowColumnJ As Long
LastRowColumnJ = Cells(Rows.Count, 1).End(xlUp).Row
range("M2:M" & LastRowColumnJ).Formula = "=IF(and(J2<=TODAY(),L2<=Today()),ROUND((TODAY()-L2)/7,1),"""")"
End Sub

I'll pick this thread up tomorrow, now.
Thank you very much for trying to help with this.
 
Upvote 0
Your code works for me.
What line is highlighted when you click debug?
Do you have any merged cells & is the sheet protected?
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,596
Members
452,658
Latest member
GStorm

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