HELP!!! I can't set formula to cell

techmaster29729

New Member
Joined
Aug 4, 2017
Messages
3
[FONT=&quot]hi i'm trying to programmatically pull a formula then add a new user to that formula and then set the cell with the new formula[/FONT]

[FONT=&quot]here's what i got[/FONT]

Code:
[COLOR=#141414][FONT=&quot]Dim SATURDAY_DEPART_TIME_INITAL As String[/FONT][/COLOR]
[COLOR=#141414][FONT=&quot]SATURDAY_DEPART_TIME_INITAL = ActiveWorkbook.Sheets("SAT").Range("H8").Formula[/FONT][/COLOR]

[COLOR=#141414][FONT=&quot]If InStr(1, SATURDAY_DEPART_TIME_INITAL, "=IFERROR") Then[/FONT][/COLOR]
[COLOR=#141414][FONT=&quot]SATURDAY_DEPART_TIME_INITAL = Replace(SATURDAY_DEPART_TIME_INITAL, "=IFERROR(", "")[/FONT][/COLOR]
[COLOR=#141414][FONT=&quot]SATURDAY_DEPART_TIME_INITAL = Replace(SATURDAY_DEPART_TIME_INITAL, "", """ & """, "")[/FONT][/COLOR]
[COLOR=#141414][FONT=&quot]End If[/FONT][/COLOR]

[COLOR=#141414][FONT=&quot]SATURDAY_DEPART_TIME_INITAL = Replace(SATURDAY_DEPART_TIME_INITAL, "))", "), " & Chr(10) & "NAME=""" & [/FONT][/COLOR][COLOR=#141414][FONT=&quot]Employee.Text[/FONT][/COLOR][COLOR=#141414][FONT=&quot] & """,IF(ISBLANK(" & LResult & "_SATURDAY_DEPART_TIME_INITAL),""""," & LResult & "_SATURDAY_DEPART_TIME_INITAL)),""" & """")[/FONT][/COLOR]

[COLOR=#141414][FONT=&quot]With New MSForms.DataObject[/FONT][/COLOR]
[COLOR=#141414][FONT=&quot].SetText SATURDAY_DEPART_TIME_INITAL[/FONT][/COLOR]
[COLOR=#141414][FONT=&quot].PutInClipboard[/FONT][/COLOR]
[COLOR=#141414][FONT=&quot]End With[/FONT][/COLOR]

[COLOR=#141414][FONT=&quot]ActiveWorkbook.Sheets("SAT").Range("H8").FormulaLocal = "=IFERROR(" & SATURDAY_DEPART_TIME_INITAL & ")"[/FONT][/COLOR]

[FONT=&quot]when i try to run the code it gives an error

[/FONT]
errr-png.11194


[FONT=&quot]any idea why its not working?[/FONT]
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Code:
Dim SAT_SATURDAY_DEPART_TIME_INITAL As StringSAT_SATURDAY_DEPART_TIME_INITAL = ActiveWorkbook.Sheets("SAT").Range("H8").Formula


If Not InStr(1, SAT_SATURDAY_DEPART_TIME_INITAL, "NAME=""" & Employee.Text & "") Then


If InStr(1, SAT_SATURDAY_DEPART_TIME_INITAL, "=IFERROR") Then
    SAT_SATURDAY_DEPART_TIME_INITAL = Replace(SAT_SATURDAY_DEPART_TIME_INITAL, "=IFERROR(", "")
    SAT_SATURDAY_DEPART_TIME_INITAL = Left(SAT_SATURDAY_DEPART_TIME_INITAL, Len(SAT_SATURDAY_DEPART_TIME_INITAL) - 4)
End If


If InStr(1, SAT_SATURDAY_DEPART_TIME_INITAL, "=IFS") Then
    SAT_SATURDAY_DEPART_TIME_INITAL = Right(SAT_SATURDAY_DEPART_TIME_INITAL, Len(SAT_SATURDAY_DEPART_TIME_INITAL) - 1)
End If


    SAT_SATURDAY_DEPART_TIME_INITAL = Replace(SAT_SATURDAY_DEPART_TIME_INITAL, "))", "), " & Chr(10) & "NAME=""" & Employee.Text & """,IF(ISBLANK(" & LResult & "_SATURDAY_DEPART_TIME_INITAL),""""," & LResult & "_SATURDAY_DEPART_TIME_INITAL))")


MyDataObj.SetText SAT_SATURDAY_DEPART_TIME_INITAL
MyDataObj.PutInClipboard


End If
ActiveWorkbook.Sheets("SAT").Range("H8").FormulaLocal = "=IFERROR(" & SAT_SATURDAY_DEPART_TIME_INITAL & "," & Chr(34) & ")"

same error....

copying the formula to the clipboard looks like it should but can't apply the formula to the cell...
 
Upvote 0
apparently me trying to set =IFERROR( with ,"") is the problem.. took out the "" in that line of code and it applied just fine... problem is I can't use =IFERROR without the ,"") at the end...
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,180
Members
453,021
Latest member
Justyna P

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