Missing parts of pasted formula when when recording macro.

leemcder

New Member
Joined
Feb 26, 2018
Messages
42
Can someone please help me? When I copy the formula below(which works) while recording a macro, it seems to have parts of the formula cut off in the code (highlighted below is what the macro creates) for example, the original formula, looks in the data sheet for "highway Tripper", as you can see in the macro recording (ive highlighted in black), it is changed to
Highw" & _
"er"")) I assume this is why the code wont work? Can someone please tell me how to stop this from happening? I'd rather not have to manually type in the formula, as I have about 15 of them.

Thanks

=SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,"Clinical Negligence"))+SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,"Financial Mis-Selling"))+SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,"Highway Tripper"))+SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,"Holiday Illness"))+SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,"Industrial Disease"))+SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,"Other PI (Non RTA)"))+SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,"SIPP"))+SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,"Solar"))++SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,"Tripping"))+SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,"Works Accident"))


Range("I5").Select
ActiveCell.FormulaR1C1 = _
"=SUM(COUNTIFS(Data!C[9],RTA!C[-8],Data!C[8],"">1/1/1900"",Data!C[12],""Yes"",Data!C[5],"""",Data!C[-3],""Clinical Negligence""))+SUM(COUNTIFS(Data!C[9],RTA!C[-8],Data!C[8],"">1/1/1900"",Data!C[12],""Yes"",Data!C[5],"""",Data!C[-3],""Financial Mis-Selling""))+SUM(COUNTIFS(Data!C[9],RTA!C[-8],Data!C[8],"">1/1/1900"",Data!C[12],""Yes"",Data!C[5],"""",Data!C[-3],"
"Highw" & _
"er""))+SUM(COUNTIFS(Data!C[9],RTA!C[-8],Data!C[8],"">1/1/1900"",Data!C[12],""Yes"",Data!C[5],"""",Data!C[-3],""Holiday Illness""))+SUM(COUNTIFS(Data!C[9],RTA!C[-8],Data!C[8],"">1/1/1900"",Data!C[12],""Yes"",Data!C[5],"""",Data!C[-3],""Industrial Disease""))+SUM(COUNTIFS(Data!C[9],RTA!C[-8],Data!C[8],"">1/1/1900"",Data!C[12],""Yes"",Data!C[5],"""",Data!C[-3],""Other " & _
"TA)""))+SUM(COUNTIFS(Data!C[9],RTA!C[-8],Data!C[8],"">1/1/1900"",Data!C[12],""Yes"",Data!C[5],"""",Data!C[-3],""SIPP""))+SUM(COUNTIFS(Data!C[9],RTA!C[-8],Data!C[8],"">1/1/1900"",Data!C[12],""Yes"",Data!C[5],"""",Data!C[-3],""Solar""))++SUM(COUNTIFS(Data!C[9],RTA!C[-8],Data!C[8],"">1/1/1900"",Data!C[12],""Yes"",Data!C[5],"""",Data!C[-3],""Tripping""))+SUM(COUNTIFS(Da" & _
"TA!C[-8],Data!C[8],"">1/1/1900"",Data!C[12],""Yes"",Data!C[5],"""",Data!C[-3],""Works Accident""))"
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
when it is being pushed to the cell the line breaks cause the problem " & _ it is not runable code and hence it fails. I have been successful in making work at times, but don't know what the real constraints are, so trial and often error
 
Upvote 0
you can change
Range("I5").Select
ActiveCell.FormulaR1C1 =

to

Range("I5").FormulaR1C1 =
 
Upvote 0
Do these two formulae give you the same result?
=SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,"Clinical Negligence"))+SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,"Financial Mis-Selling"))
=SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,{"Clinical Negligence","Financial Mis-Selling"}))
 
Upvote 0
Do these two formulae give you the same result?
=SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,"Clinical Negligence"))+SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,"Financial Mis-Selling"))
=SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,{"Clinical Negligence","Financial Mis-Selling"}))

Thanks for the reply. Those formulae don't work, unfortunately. They're missing out a large chunk of the countifs.
 
Upvote 0
Do they give the same result?
 
Upvote 0
Do they give the same result?
Hi, what do you mean my same result? As a working formula? or working when I paste when recording the macro? This formula doesn't contain all the conditions as the original formula, so the result is different. Thanks
 
Upvote 0
I was thinking

=SUM(COUNTIFS(Data!R:R,RTA!A:A,Data!Q:Q,">1/1/1900",Data!U:U,"Yes",Data!N:N,"",Data!F:F,OR("Clinical Negligence","Financial Mis-Selling","Highway Tripper","Holiday Illness","Industrial Disease","SIPP","Solar","Tripping","Works Accident")))

but noticed the beginning of an Array in Fluffs test

I can't test this so it may just fall over
 
Upvote 0
Hi, what do you mean my same result? As a working formula? or working when I paste when recording the macro? This formula doesn't contain all the conditions as the original formula, so the result is different. Thanks

What I mean is, if they both give the same result (as a formula), you can continue building the formula in the same manner. That will drastically reduce the length of your formula, hopefully to a point where you can record it.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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