Macro - Issue with IF statement being pasted into Cells

grantboshart

New Member
Joined
Jul 1, 2015
Messages
49
Hello all,

I am currently having an issue with the below formula being pasted into a cell.formula as shown. If I take away the If(C12<>"", , ) then the formula pastes just fine. when I paste the formula directly into a cell, it also works perfectly. Is there a way to have the macro not worry about the actual formula and just paste is word for word? Script below
vVv


Sub DefaultSlopes()

If MsgBox("Are you sure you want to change all pipe slopes back to default?" & vbNewLine & "This action cannot be reversed.", vbYesNo + vbExclamation, "Just making sure that wasn't an accident.") = vbYes Then

Range("R12:R100").Formula(I have also tried .Value) = "=IF(C12<>"",IF(P12=24, 0.18, IF(P12=30,0.13,IF(P12=36, 0.11, 0.1))),"")"

Else
End If
End Sub


Thanks!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
have you tried recording that paste action
 
Upvote 0
I would try that but I am not aware of a way to record a msgbox. I want the message box as a safety net for people who may accidentally hit the button.
 
Upvote 0
I remember "" must have """". Does it help?
 
Upvote 0
you only need to record the formula being placed, the rest can be cobbled together
 
Upvote 0
You nee to use a pair of double quotes for each double quote you want in the formula, otherwise VBA thinks you're ending the string.

Range("R12:R100").Formula(I have also tried .Value) = "=IF(C12<>"""",IF(P12=24, 0.18, IF(P12=30,0.13,IF(P12=36, 0.11, 0.1))),"""")"
 
Upvote 0
You nee to use a pair of double quotes for each double quote you want in the formula, otherwise VBA thinks you're ending the string.

Range("R12:R100").Formula(I have also tried .Value) = "=IF(C12<>"""",IF(P12=24, 0.18, IF(P12=30,0.13,IF(P12=36, 0.11, 0.1))),"""")"

that is just what I needed to hear. Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,482
Messages
6,125,060
Members
449,206
Latest member
Healthydogs

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