Strange Formula Tranformation When Recording A Macro

adamas

New Member
Joined
Feb 3, 2009
Messages
13
Hey there, guys!

I'm trying to compile a relatively simple Macros by recording some actions and then adjust the resulting script, but I've stumbled into a particularly weird issue.

So, I'm recording a Macros that pastes a formula into a cell.
- This is the formula I want the macros to paste:
Code:
=IF(AND(AND(O7<>"some-text-value",O7<>"some-text-value",O7<>"some-text-value"),OR(W7="some-text-value",W7="some-text-value")),IF(OR(DN7="",DN7=0),"",IF(OR(O7="some-text-value",O7="some-text-value",O7="some-text-value"),"",IF(O7="some-text-value","Hitri","Other"))),"")
Meaning what I do is simply: turn macro recording on, select a cell, and copy/paste the formula above into it. Then stop and I get some VBA code.

- Here's the resulting code, with issue area in bold:
Code:
    ActiveCell.FormulaR1C1 = _        "=IF(AND(AND(RC[-106]<>""some-text-value"",RC[-106]<>""some-text-value"",RC[-106]<>""some-text-value""),OR(RC[-98]=""some-text-value"",RC[-98]=""some-text-value"")),IF(OR(RC[-3]="""",RC[-3]=0),"""",IF(OR(RC[-106]=""some-text-value"",RC[-106]=""some-text-value"",RC[-106]=""some-text-value""),"""",IF(RC[-106]=""some-text-value"","[B]"Hitr" & _[/B]
[B]        "her""))),"""")"[/B]


So instead of the original formula I need (issue area in bold):
Code:
=IF(AND(AND(O7<>"some-text-value",O7<>"some-text-value",O7<>"some-text-value"),OR(W7="some-text-value",W7="some-text-value")),IF(OR(DN7="",DN7=0),"",IF(OR(O7="some-text-value",O7="some-text-value",O7="some-text-value"),"",IF(O7="some-text-value",[B]"Hitri","Other"))),"")[/B]
I get (issue area in bold):
Code:
=IF(AND(AND(O7<>"some-text-value",O7<>"some-text-value",O7<>"some-text-value"),OR(W7="some-text-value",W7="some-text-value")),IF(OR(DN7="",DN7=0),"",IF(OR(O7="some-text-value",O7="some-text-value",O7="some-text-value"),"",IF(O7="some-text-value",[B]"Hitrher"))),"")[/B]

Basically the problem is that when recording the macro Excel doesn't correctly transfer this piece:
Code:
"Hitri","Other"))),"")
And on the out I get:
Code:
"Hitrher"))),"")

Could anyone be so kind to help me fix the resulting VBA code manually for this to properly match the original formula? :)




P.S. I did try to manually fix the text by adding missing pieces to both words:
Code:
"Hitr[B]i[/B]" & _
       "[B]Ot[/B]her""))),"""")"
BUT I'm still missing the "," part between the two words, and (for the love of god!) I can't figure out how or what to append to do this.
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try changing the bold bit from this:

Rich (BB code):
"",""Hitr" & _
        "her""))),"""")"

To this:

Rich (BB code):
"",""Hitri"",""Other""))),"""")"
 
Upvote 0
.
.

I think the problem is you need double quotation marks ("") surrounding the text in your formula, i.e. "Other" must be changed to ""Other"".
 
Upvote 0
Guys, thanks so much! That line break thing was indeed the issue it seems.

I really do appreciate you both taking the time to look at this! /me tips his imaginary hat
 
Upvote 0

Forum statistics

Threads
1,216,222
Messages
6,129,589
Members
449,520
Latest member
TBFrieds

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