Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting non-adjacent columns

Status
Not open for further replies.

sedgely

Technical User
Feb 21, 2002
406
GB
i am trying to set the column width of several columns that are not adjacent to each other e.g. column A, column C, column Z

the code i have used is :

Private Sub CommandButton1_Click()
With Worksheets("sheet1").Columns("A:C")
.ColumnWidth = 15
End With
End Sub

this works great for adjacent columns, but how do i specify a range of columns that are non-adjacent?

Craig
 
use Array to list them
record a macro to do it! and you will see
 
Hi sedgely,

There are various ways, but in keeping with what you have, use ..

Code:
With Worksheets("sheet1").Columns("A:A,C:C,Z:Z")

Enjoy,
Tony
 
try this and see if it works

Private Sub CommandButton1_Click()
Worksheets("sheet1").Range("A:A,C:C,Z:Z").Select
Selection.ColumnWidth = 15
End Sub
 


I think you can do

Code:
Worksheets("sheet1").Columns("A:A,C:C,Z:Z").ColumnWidth = 15
 
It might be easier to combine (UNION) these columns into one object:
Code:
Dim WidthCols As Range
Set WidthCols = Union(Columns("A"), Columns("C"))
WidthCols.ColumnWidth = 10



Dan.
 
Hey Guys thanks for the prompt replies and many suggestions, have found that the following solution works well so am gonna use that.

Worksheets("Sheet1").Range("A:A,C:C").ColumnWidth = 15


Again many thanks to all. [2ThumbsUp]

Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top