Help with Autofit based on criteria in Col B

Anfinsen

Board Regular
Joined
Apr 11, 2023
Messages
144
Office Version
  1. 365
Platform
  1. Windows
Hi All,
I know what line is causing me trouble in this code, I just don't know how to fix it.

I am trying to autofit the entire row where data exists in column B, starting at row 6. I think this is incorrect "c.EntireRow.AutoFit", I just don't know how to reference the row of the "active cell"
Any help would be greatly appreciated.

VBA Code:
Sub FitDescRows()
  Dim c As Range, sh1 As Worksheet
  Set sh1 = Sheets("Pick List")
  For Each c In sh1.Range("B6", sh1.Cells(Rows.Count, "B").End(xlUp))
    If c.Value <> "" Then
      c.EntireRow.AutoFit
    End If
  Next

End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
There is nothing wrong with that code.
What error are you getting?
 
Upvote 1
Solution
There is nothing wrong with that code.
What error are you getting?
Never mind, I am an idiot. I am working on some previous code handed to me, and I found where they had the same range set to WrapText = True, so it looked like my code wasn't autofitting these, because they already were as part of the previous "WrapText" code. I'll mark this solved, unless there is an "I'm an idiot" option" :)
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,212
Members
453,023
Latest member
alabaz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top