Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
String width not exceed column width
Given the font and size (Arial, 10), is it possible to calculate how wide a
given string will be? I have 120 columns that are 1 character wide (12 pixels). I would like to know how many columns a given string will cover. Thank You! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
String width not exceed column width
Difficult for a proportional font.
-- Gary''s Student - gsnu200750 "Norm Lundquist" wrote: Given the font and size (Arial, 10), is it possible to calculate how wide a given string will be? I have 120 columns that are 1 character wide (12 pixels). I would like to know how many columns a given string will cover. Thank You! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
String width not exceed column width
LEN(string) will give the number of characters in the string (includes
spaces). Since each column is one character wide, then this formula would be real close to the actual number of columns used. Keep in mind not all characters are the same width. Mike F "Norm Lundquist" wrote in message ... Given the font and size (Arial, 10), is it possible to calculate how wide a given string will be? I have 120 columns that are 1 character wide (12 pixels). I would like to know how many columns a given string will cover. Thank You! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
String width not exceed column width
See if this site helps you:
http://office.microsoft.com/en-us/ex...CL100570551033 "Norm Lundquist" wrote: Given the font and size (Arial, 10), is it possible to calculate how wide a given string will be? I have 120 columns that are 1 character wide (12 pixels). I would like to know how many columns a given string will cover. Thank You! |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
String width not exceed column width
However, I just did a test and 69 characters used 33 columns. As Gary's
Student said, a really difficult answer. Mike F "Mike Fogleman" wrote in message m... LEN(string) will give the number of characters in the string (includes spaces). Since each column is one character wide, then this formula would be real close to the actual number of columns used. Keep in mind not all characters are the same width. Mike F "Norm Lundquist" wrote in message ... Given the font and size (Arial, 10), is it possible to calculate how wide a given string will be? I have 120 columns that are 1 character wide (12 pixels). I would like to know how many columns a given string will cover. Thank You! |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
String width not exceed column width
In theory it's possible to calculate the width of each known character,
cater for mixed formats, etc. But the easiest way is to copy the text to a suitably formatted cell in an otherwise empty column, perhaps in a hidden sheet. Then do an Autofit and check the column width. It's also possible to do similar in a Textbox, if anything slightly more accurate as cells have a little padding which varies according to xl version, but much more code. Sub test4() Dim rTmp As Range Set rTmp = Worksheets("Sheet3").Range("A1") rTmp(1).EntireColumn.ClearContents rTmp.Font.Name = "Arial" rTmp.Font.Size = 10 rTmp.Value = "Some text of unknown width" rTmp(1).EntireColumn.AutoFit MsgBox rTmp(1).EntireColumn.Width End Sub Regards, Peter T "Norm Lundquist" wrote in message ... Given the font and size (Arial, 10), is it possible to calculate how wide a given string will be? I have 120 columns that are 1 character wide (12 pixels). I would like to know how many columns a given string will cover. Thank You! |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
String width not exceed column width
Thanks, Peter! Autofitting the column will get me close enough and any extra
padding is no problem. Nice, simple solution ... let Excel do the work! "Peter T" wrote: In theory it's possible to calculate the width of each known character, cater for mixed formats, etc. But the easiest way is to copy the text to a suitably formatted cell in an otherwise empty column, perhaps in a hidden sheet. Then do an Autofit and check the column width. It's also possible to do similar in a Textbox, if anything slightly more accurate as cells have a little padding which varies according to xl version, but much more code. Sub test4() Dim rTmp As Range Set rTmp = Worksheets("Sheet3").Range("A1") rTmp(1).EntireColumn.ClearContents rTmp.Font.Name = "Arial" rTmp.Font.Size = 10 rTmp.Value = "Some text of unknown width" rTmp(1).EntireColumn.AutoFit MsgBox rTmp(1).EntireColumn.Width End Sub Regards, Peter T "Norm Lundquist" wrote in message ... Given the font and size (Arial, 10), is it possible to calculate how wide a given string will be? I have 120 columns that are 1 character wide (12 pixels). I would like to know how many columns a given string will cover. Thank You! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Change Cell Width WITHOUT changing Column width | Excel Discussion (Misc queries) | |||
Create a macro which takes a column name and width and sets the column width to what it should be | Excel Programming | |||
How to make cell width different than the column width it lies in | Excel Discussion (Misc queries) | |||
Set Column Width Based On Total Width Of Other Columns | Excel Programming |