troubleshooting Question

Abstract this sub

Avatar of NVIT
NVITFlag for United States of America asked on
Microsoft ExcelVBAMicrosoft OfficeMicrosoft Applications
6 Comments1 Solution160 ViewsLast Modified:
I recorded this. It specifically finds the PM column header.
Then sets the column width.

Sub Set_Col_Wid_PM()
    Cells.Find(What:="PM", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
        MatchCase:=True, SearchFormat:=False).Activate
    Selection.ColumnWidth = 5.14
End Sub

I'd like to abstract this so I can pass the column name and desired width. e.g.

= Set_Col_Wid("PM", 5.14)

Is there a way to 'generalize' Columns("E:E").Select so that it knows what column to select, regardless of its location?

Can you help?
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros