decadence
Well-known Member
- Joined
- Oct 9, 2015
- Messages
- 525
- Office Version
- 365
- 2016
- 2013
- 2010
- 2007
- Platform
- Windows
Hi, I am trying to determine the column width but not sure how. What I wold like to do is:
If it is smaller than a specific number then auto fit that column
If the width is bigger than that number then set the column width to that number
Can someone help please.
Here is What I have so far
If it is smaller than a specific number then auto fit that column
If the width is bigger than that number then set the column width to that number
Can someone help please.
Here is What I have so far
Code:
Sub ColWidth()
Dim x2 As range, Rng As range
Set Rng = range("A1:H1")
For Each x2 In Rng
If InStr(1, x2.Value, "Apple") > 0 Then
If x2.Width <> 5 Then
x2.EntireColumn.ColumnWidth = 5
End If
ElseIf InStr(1, x2.Value, "Banana") > 0 Then
If x2.Width <> 12.5 Then
x2.EntireColumn.ColumnWidth = 12.5
End If
ElseIf InStr(1, x2.Value, "Orange") > 0 Then
If x2.Width <> 20 Then
x2.EntireColumn.ColumnWidth = 20
End If
End If
Next x2
End Sub