Hi, I wonder whether someone may be able to help me please.
I'm relatively new to VB, so a lot of my code is very long winded, an example of which is below:
'***First Range
LastRow = Cells(Rows.count, "B").End(xlUp).Row
If LastRow >= StartRow Then
With Range("B7:D" & LastRow)
With .Font
.Name = "Lucida Sans"
.Size = 10
End With
End With
End If
With Range("D7:D" & LastRow)
.NumberFormat = "#,##0.00"
.HorizontalAlignment = xlCenter
End With
LastRow = Range("B" & Rows.count).End(xlUp).Row
For i = 7 To LastRow
With Range("C" & i)
X = Split(.Value, ",")
If UBound(X) = 1 Then .Value = Trim(X(1)) & " " & Trim(X(0))
End With
Next i
With Range("B7:D" & LastRow)
.sort Key1:=.Cells(1, 1), Order1:=xlAscending
End With
'***Second Range
LastRow = Cells(Rows.count, "G").End(xlUp).Row
If LastRow >= StartRow Then
With Range("G7:H" & LastRow)
With .Font
.Name = "Lucida Sans"
.Size = 10
End With
End With
End If
With Range("H7:H" & LastRow)
.NumberFormat = "#,##0.00"
.HorizontalAlignment = xlCenter
End With
LastRow = Range("G" & Rows.count).End(xlUp).Row
For i = 7 To LastRow
With Range("G" & i)
X = Split(.Value, ",")
If UBound(X) = 1 Then .Value = Trim(X(1)) & " " & Trim(X(0))
End With
Next i
With Range("G7:H" & LastRow)
.sort Key1:=.Cells(1, 1), Order1:=xlAscending
End With
The code applies formatting to two ranges within a given sheet in my workbook, but as I mentioned at the start, it's messy and 'long winded'.
I just wondered whether someone with more experience, could possibly look at this please and offer some guidance on how I may be able to streamline the code.
Many thanks and kind regards
Bookmarks