ScottishPeter
New Member
- Joined
- Apr 22, 2023
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
Hello, i'm trying to change some script to ensure rows automatically adjust height based on the text that populates the cell.
On some occasions the cells wont have to be adjusted, but sometimes they will. Hence trying to do it automatically.
The AutoFit code is towards the bottom.
Currently VBA is:
Thanks
On some occasions the cells wont have to be adjusted, but sometimes they will. Hence trying to do it automatically.
The AutoFit code is towards the bottom.
Currently VBA is:
VBA Code:
Sub listWine()
Dim n As Long
Dim tcbCode As String
Dim findRange As Range
Dim wsData As Worksheet
Dim wsList As Worksheet
Set wsData = Worksheets("Wine Data")
Set wsList = Worksheets("Wine List")
tcbCode = Range("B" & ActiveCell.Row).Value
If tcbCode = "" Then
MsgBox "kindly select Proper Wine!", vbCritical
Exit Sub
End If
Set findRange = wsData.Range("B:B").Find(tcbCode, , xlValues, xlWhole)
If Not findRange Is Nothing Then
n = wsList.Range("A" & Rows.Count).End(xlUp).Row + 1
wsList.Range("A" & n).Value = wsData.Range("B" & findRange.Row).Value
wsList.Range("B" & n).Value = wsData.Range("I" & findRange.Row).Value
wsList.Range("C" & n).Value = wsData.Range("C" & findRange.Row).Value
wsList.Range("D" & n).Value = wsData.Range("F" & findRange.Row).Value
wsList.Range("E" & n).Value = wsData.Range("T" & findRange.Row).Value
wsList.Range("F" & n).Value = wsData.Range("D" & findRange.Row).Value
wsList.Range("G" & n).Value = wsData.Range("P" & findRange.Row).Value
wsList.Range("H" & n).Value = wsData.Range("R" & findRange.Row).Value
wsList.Range("J" & n).Formula = "=IF(I" & n & "<>0,1 - ((H" & n & " * 1.2) / I" & n & "), """")"
wsList.Range("K" & n).Formula = "=IF(I" & n & "<>0,1 + ((I" & n & " / 1.2) - H" & n & ") - 1, """")"
wsList.Range("M" & n).Formula = "=IF(L" & n & "<>0,1 - (((H" & n & " / 6) * 1.2) / L" & n & "), """")"
wsList.Range("O" & n).Formula = "=IF(N" & n & "<>0,1 - (((H" & n & " / 4.28571) * 1.2) / N" & n & "), """")"
wsList.Range("Q" & n).Formula = "=IF(P" & n & "<>0,1 - (((H" & n & " / 3) * 1.2) / P" & n & "), """")"
wsList.Range("A" & n + 1).Value = wsData.Range("S" & findRange.Row).Value
wsList.Range("A" & n + 1 & ":Q" & n + 1).Merge
wsList.Range("A" & n + 1).WrapText = True
wsList.Range("A" & n + 1).EntireRow.AutoFit
wsList.Range("A" & n + 1 & ":Q" & n + 1).Interior.ColorIndex = 15
wsList.Range("A" & n + 1).HorizontalAlignment = xlCenter
Else
MsgBox "Wine Associated with this code not found in data!", vbInformation
End If
End Sub
Thanks