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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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