MS Word breaks up my VBA codes....

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Hello, I am trying to write up some of my excel formulas and codes, but whenever I type them in word breaks up the syntax. For example I will type in this:

=IF(COUNTIF(C:C,"<0")<$E$1,"Too few values",AVERAGEIF(INDEX(C:C,LARGE(IF(C:C<0,ROW(C:C),""),$E$1)):INDEX(C:C,MATCH(2,1/(C:C<0))),"<0"))


but what I get is this:

=IF(COUNTIF(C:C,"<0")<$E$1,"Too
few values",AVERAGEIF(INDEX(C:C,LARGE(IF(C:C<0,ROW(C:C),""),$E$1)):INDEX(C:C,MATCH(2,1/(C:C<0))),"<0"))

So it looks wonky on the page. I can't figure out why Word keeps kicking that sentence down to the next line - anyone have any ideas? Thanks,
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
It is because the total length of your string is 135 characters which is more that word can write on one line of your page,, so Word maked an effort to break the line at the end of a word ( usually sensible), which is detects as being a space. If you change the font size to someting very small and possible change the orientation to landscape you can get it on one line. ( probably not what you want to do)
the "values",AVERAGEIF(INDEX(C:C,LARGE(IF(C:C<0,ROW(C:C),""),$E$1)):INDEX(C:C,MATCH(2,1/(C:C<0))),"<0"))" is 99 character word !!! i.e no spaces!!
 
Upvote 0
It is because the total length of your string is 135 characters which is more that word can write on one line of your page,, so Word maked an effort to break the line at the end of a word ( usually sensible), which is detects as being a space. If you change the font size to someting very small and possible change the orientation to landscape you can get it on one line. ( probably not what you want to do)
Oh, okay that explains why I could not get it to stop after going through all the formatting and paragraph settings and such. I agree that it makes sense with a regular type of sentence, but in this case I am making a manual for the rest of the team on all of the codes we use. So I need to keep the syntax all connected. I tried using text boxes and shapes and such with no luck, so I suspect that this same rule applies to those as well.

I don't mind Word breaking it up into two lines, I just rather it did it at the end of the first line and I can't seem to get around that... Thanks for your input, it is appreciated.
 
Upvote 0
Shift+Space should give you a non-breaking space (or Ctrl+Shift+Space? Can't recall exactly...).

But even then at some point something is going to wrap around viewing in page layout.
 
Upvote 0

Forum statistics

Threads
1,223,396
Messages
6,171,864
Members
452,427
Latest member
samk379

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