vbscript to run formula down on button click

projectile

Board Regular
Joined
Dec 14, 2007
Messages
193
Trying to create button, so when clicked, it will automatically run formula down column L , if column A contains text. However Excel is complaining about the IF statement I'm trying to run down.

Doen't like the line in RED

Using Excel 2003.



Private Sub runFormula_Click()
Dim LastRow As Long
With ActiveSheet

LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1

.Range("L" & LastRow).Resize(1, 3).FormulaR1C1 = "=IF(LEFT(F6,2)="--","NO_SWIPE",IF(C6=105,IF(F6<=SHIFTS!$C$5,"on_time",F6-SHIFTS!$C$5),IF(C6=106,IF(F6<=SHIFTS!$C$6,"on_time",F6-SHIFTS!$C$6),IF(C6=99,IF(F6<=SHIFTS!$C$7,"on_time",F6-SHIFTS!$C$7),IF(C6=102,IF(F6<=SHIFTS!$C$8,"on_time",F6-SHIFTS!$C$8),IF(F6<=SHIFTS!$C$4,"on_time",F6-SHIFTS!$C$4))))))"
.Range("L" & LastRow).Resize(1, 1).Name = "Is late?"

End With
End Sub


any ideas?
 

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.
Your formula is in A1 notation, not R1C1 so use Range.Formula rather than Range.FormulaR1C1. Also, you need to double all quote marks so "abc" should be ""abc"".
 
Upvote 0
This compiles OK:

Code:
.Range("L" & Lastrow).Resize(1, 3).Formula = "=IF(LEFT(F6,2)=""--"",""NO_SWIPE"",IF(C6=105,IF(F6<=SHIFTS!$C$5,""on_time"",F6-SHIFTS!$C$5),IF(C6=106,IF(F6<=SHIFTS!$C$6,""on_time"",F6-SHIFTS!$C$6),IF(C6=99,IF(F6<=SHIFTS!$C$7,""on_time"",F6-SHIFTS!$C$7),IF(C6=102,IF(F6<=SHIFTS!$C$8,""on_time"",F6-SHIFTS!$C$8),IF(F6<=SHIFTS!$C$4,""on_time"",F6-SHIFTS!$C$4))))))"

Not that your formula is in A1 reference style so you should be using the Formula property, not the FormulaR1C1 property.
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,508
Members
452,918
Latest member
Davion615

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