Saqib Husain
asked on
Text spanning multiple columns
In Excel VBA is there a way to know how many columns would a text string span if it is wider than the column it is in?
eg
Wordwrap is turned of.
If there is text in D5 and it is wider than column 5 which column would it end in?
This is because I have overlapping texts and I have to move the other text over so that it does not overlap.
eg
Wordwrap is turned of.
If there is text in D5 and it is wider than column 5 which column would it end in?
This is because I have overlapping texts and I have to move the other text over so that it does not overlap.
Have you tried the TextWidth function? You can compare the results to the width of the current and empty columns to the immediate right.
What are you trying to accomplish?
ASKER
I am unable to find any help on this. How do I use it?
ASKER
Martin, I have explained all in the question.
In VBA you can do this.
Columns("D").AutoFit
Columns("D").AutoFit
This is because I have overlapping texts and I have to move the other text over so that it does not overlap.OR tried to implement the Wordwrap in macro?
Range.WrapText property (Excel)
https://docs.microsoft.com/en-us/office/vba/api/excel.range.wraptext
ASKER
Martin, I do not want to change the column widths... unless you suggest to change the autofit the column, measure it and then restore it, in which case the macro would take a lot of time as there are thousands of lines. I was hoping for direct calculation of length. Thinking aloud I put an autofit textbox somewhere on the sheet, assign the text and then measure the box. Do you think this could be worthwhile?
Ryan Chong, I do not want to wrap the text.
Ryan Chong, I do not want to wrap the text.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I’m glad I was able to help.
If you expand the “Full Biography" section of my profile you’ll find links to some articles I’ve written that may interest you including a new one concerning your Experts Exchange rank.
Marty - Microsoft MVP 2009 to 2017
Experts Exchange Most Valuable Expert (MVE) 2015, 2017
Experts Exchange Top Expert Visual Basic Classic 2012 to 2018
Experts Exchange Top Expert VBA 2018
Experts Exchange Distinguished Expert in Excel 2018
If you expand the “Full Biography" section of my profile you’ll find links to some articles I’ve written that may interest you including a new one concerning your Experts Exchange rank.
Marty - Microsoft MVP 2009 to 2017
Experts Exchange Most Valuable Expert (MVE) 2015, 2017
Experts Exchange Top Expert Visual Basic Classic 2012 to 2018
Experts Exchange Top Expert VBA 2018
Experts Exchange Distinguished Expert in Excel 2018