ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Determine width of entire visible area and width of labels (https://www.excelbanter.com/excel-programming/408020-determine-width-entire-visible-area-width-labels.html)

[email protected]

Determine width of entire visible area and width of labels
 
Is it possible to get the width of all of the visible columns?
Would this work?
Worksheets("Sheet1").Activate
Windows(1).VisibleRange.Width

Would it be possible some how predetermine the width of a label on a
sheet, before entering text into it? Basically I would like to know
the width of the label given a font and some text before adding the
text to the label. The reason I would like to do this is to test to
see if the label is going to go outside of the visible range (which
results an error).

I was thinking that I might have to put the label on a hidden sheet
first and test its width there and then put the text on the visible
sheet. Would a label on a dialog box with same font/text have the
same width as one in a sheet?

Thanks,
David

[email protected]

Determine width of entire visible area and width of labels
 
I can find total width of visible columns by doing this:
Dim total_width As Long
total_width = 0
Do While counter < 255
total_width = total_width + Sheet1.Cells(1, counter + 1).Width
counter = counter + 1
Loop
MsgBox ("test2: " & total_width)

But is this the fastest/most efficient way of doing it, is there some
kind of sheet property that gives the entire width of the sheet?



On Mar 19, 6:30 pm, "
wrote:
Is it possible to get the width of all of the visible columns?
Would this work?
Worksheets("Sheet1").Activate
Windows(1).VisibleRange.Width

Would it be possible some how predetermine the width of a label on a
sheet, before entering text into it? Basically I would like to know
the width of the label given a font and some text before adding the
text to the label. The reason I would like to do this is to test to
see if the label is going to go outside of the visible range (which
results an error).

I was thinking that I might have to put the label on a hidden sheet
first and test its width there and then put the text on the visible
sheet. Would a label on a dialog box with same font/text have the
same width as one in a sheet?

Thanks,
David



Rick Rothstein \(MVP - VB\)[_1518_]

Determine width of entire visible area and width of labels
 
First off, your '<255' should be '<256', otherwise your total is wrong. But
you don't have to do that at all as this single statement will return the
value you seek...

MsgBox "Test3: " & Columns.Width

Just to note, doing it this way gives the total visible column width for the
ActiveSheet. If you wanted to do this for a specified sheet, say Sheet2,
then you would do this...

MsgBox "Test3: " & Worksheets("Sheet2").Columns.Width

Rick


wrote in message
...
I can find total width of visible columns by doing this:
Dim total_width As Long
total_width = 0
Do While counter < 255
total_width = total_width + Sheet1.Cells(1, counter + 1).Width
counter = counter + 1
Loop
MsgBox ("test2: " & total_width)

But is this the fastest/most efficient way of doing it, is there some
kind of sheet property that gives the entire width of the sheet?



On Mar 19, 6:30 pm, "
wrote:
Is it possible to get the width of all of the visible columns?
Would this work?
Worksheets("Sheet1").Activate
Windows(1).VisibleRange.Width

Would it be possible some how predetermine the width of a label on a
sheet, before entering text into it? Basically I would like to know
the width of the label given a font and some text before adding the
text to the label. The reason I would like to do this is to test to
see if the label is going to go outside of the visible range (which
results an error).

I was thinking that I might have to put the label on a hidden sheet
first and test its width there and then put the text on the visible
sheet. Would a label on a dialog box with same font/text have the
same width as one in a sheet?

Thanks,
David





All times are GMT +1. The time now is 04:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com