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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Column Width

Status
Not open for further replies.

bdjb

Technical User
Oct 29, 2002
292
US
Hello,
I'm using the following code to set my column width in a Macro, but it doesn't always work. Is there a better way to do it? I have about 15 different columns that I need to set.

Excel 2003

Thanks,
 
Geez, that would have been helpful [purpleface]

Search = Cells.Find(what:="Account No.", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Selection.ColumnWidth = 16
 



Code:
    Dim rFound As Range
    Set rFound = Cells.Find("Account No.")
        
    If Not rFound Is Nothing Then
        rFound.EntireColumn.ColumnWidth = 16
    End If
Unless you KNOW where the ActiveCell is and you want to search AFTER that point, then the other arguments are not usually necessary.

What I do is, my HEADINGS are almost always in row 1...
Code:
    Dim rFound As Range
    Set rFound = [b]Rows(1)[/b].Find("Account No.")
        
    If Not rFound Is Nothing Then
        rFound.EntireColumn.ColumnWidth = 16
    End If
but that's no big deal.


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 



Notice that NOTHING gets selected!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thank you very much, that looks like a better method.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top