Your example workbooks are very helpful. Earlier, it wasn't clear that you were using "IF", "&" and such other formulas in addition to the LookUp formulas.
So here's a possible fix to hide empty rows, or else Auto-fit their row height.
Dim ws as worksheet
For Each ws in ThisWorkbook 'this would run the loop for all worksheets
With ThisWorkbook.ws
For x = 6 To 57 Step 1 'Replace 6 and 57 with the starting row and last row [I've chosen them based on the TR-A worksheet]
If .Range("A" & x) = "" Then
.Range("A" & x).EntireRow.Hidden = True 'So if the cell is blank, the row would be auto-hidden, irrespective of whether it has merged cells or not
Else 'The row is not blank and needs to be auto-fit.
Call Row_Autofit(ws.name, x)
End If
Next x 'Go to Next Row
End With
Next 'Go to next worksheet
'The following procedure is for auto-fitting rows
Sub Row_Autofit(sWs as String, iRowNum As Integer)
Dim sMerged_Range As String, sStart_Cell As String
Dim dStart_Cell_Width As Double, dMerged_Range_Width As Double, dStart_Cell_ColWidth As Double
Dim iMergeLastCol As Integer, rMerge As Range
With ThisWorkbook.Worksheets(sWs)
If IsNull(.Rows(x).MergeCells) = True Then 'checks whether or not the row has any merged cells
If .Cells(x, 1).MergeCells = True Then
Set rMerge = .Cells(x, 1).MergeArea
iMergeLastCol = 24
sMerged_Range = "A" & x & ":X" & x
sStart_Cell = "A" & x
dMerged_Range_Width = .Range(sMerged_Range).Width
dStart_Cell_Width = .Range(sStart_Cell).Width
dStart_Cell_ColWidth = .Range(sStart_Cell).ColumnWidth
.Range(sMerged_Range).UnMerge
.Range(sStart_Cell).ColumnWidth = dStart_Cell_ColWidth * dMerged_Range_Width / dStart_Cell_Width
.Range(sStart_Cell).Rows.AutoFit
.Range(sMerged_Range).Merge
.Range(sStart_Cell).ColumnWidth = dStart_Cell_ColWidth
Set rMerge = Nothing
End If
Else
.Rows(x).AutoFit
End If
End With
End Sub
You might need to tweak the code slightly, but it should be able to perform what you desire.
Good luck!
Bookmarks