I made a short VBA code which basically just AutoFits text/content inside cells. I recorded this macro and then remade it so that the code would run through the whole sheet:
Sub Macro3()
Dim lastRowIndex As Integer
Dim rowIndex As Integer
lastRowIndex = 2600
For rowIndex = 0 To lastRowIndex
If ActiveSheet.Cells(rowIndex, 1).Value <> "" Then
If ActiveSheet.Rows(rowIndex).RowHeight < 10.7 Then
If ActiveSheet.Rows(rowIndex).RowHeight > 8 Then
ActiveSheet.Rows(rowIndex).Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Rows.AutoFit
End If
End If
End If
Next rowIndex
End Sub
The application stops at the IF conditions. They're there because I don't want to affect all the cells, just the ones I need to modify.
When I try to run this code it gives me a this Runtime Error "1004" - Aplication-defined or Object-defined error. I have no idea why...
I tried putting Option Explicit above the code since I read somewhere it then gives you a more detailed information about the error but that doesn't seem to work either. I've never really used VBA before so I have no clue what's the reason for the error.
(Also why is a part of the code above shifting to the left? I cant fix it)