VBA: How to dynamically adjust the height of rows based on cell content without overwriting existing formatting?
I've searched everywhere and can't find a clear answer. I've been struggling with this for a few days now and could really use some help. I'm currently working on an Excel VBA project where I need to automatically adjust the heights of specific rows based on the content of their cells. The challenge is to ensure that any existing row formatting (like colors and borders) remains intact after I change the row heights. I've tried using the `AutoFit` method, but it seems to reset some of the formatting I have set. Here's a snippet of what I've been using: ```vba Sub AdjustRowHeights() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") Dim lastRow As Long lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row Dim i As Long For i = 1 To lastRow With ws.Rows(i) .RowHeight = 20 ' Resetting height to a default value .AutoFit ' This modifies formatting End With Next i End Sub ``` When I run this code, I've noticed that some of my rows lose their custom background colors. I need a solution that dynamically sets the height based on the content while preserving the formatting for each row. Any ideas on how I can achieve this without losing the existing styles? Iām using Excel 2016 and my project is quite complex, so Iām looking for a robust solution that won't require extensive rewriting of my code. This is part of a larger service I'm building. Any help would be greatly appreciated! I'm working on a service that needs to handle this. This issue appeared after updating to Vba 3.11. I'd really appreciate any guidance on this.