Hi Guys
Happy Halloween! ?? ??
I have produced the below code to look at cell data to check if the contents is not above 100 characters. If it is, it removes everything above 100 and places it in the next column with the current data already in that cell. Then later, it will check that cell containing old and new data to also see if contents are above 100 characters and so on until last column is complete. This works fine but I am struggling to retain 'whole words' because I don't want part of a word cutting in half so to speak! If the cut happens within a word I need it to remove the whole word and transfer it to the next column as above. Hope this makes sense.
Happy Halloween! ?? ??
I have produced the below code to look at cell data to check if the contents is not above 100 characters. If it is, it removes everything above 100 and places it in the next column with the current data already in that cell. Then later, it will check that cell containing old and new data to also see if contents are above 100 characters and so on until last column is complete. This works fine but I am struggling to retain 'whole words' because I don't want part of a word cutting in half so to speak! If the cut happens within a word I need it to remove the whole word and transfer it to the next column as above. Hope this makes sense.
VBA Code:
For Each cell In rng
Dim Orders As Worksheet: Set Orders = Sheets("Orders")
Dim LstCol As Long: LstCol = Orders.Range("a1").CurrentRegion.Columns.Count
Dim LstRW As Long: LstRW = Orders.Range("a1").CurrentRegion.Rows.Count
Dim rng As Range: Set rng = Orders.Range("M2:M" & LstRW & ",O2:O" & LstRW & " ,P2:P" & LstRW)
Dim cell As Range
Dim AddressField As String
Dim AFCLength As Integer
If cell.Address = "$O$2" Then Stop
AFCLength = _
Len(cell.Value & cell.Offset(, 2).Value2 & cell.Offset(, 3).Value2)
AddressField = cell.Value2
If Len(AddressField) > 100 Then
Sheets("Royal Mail").Range("j" & cell.Row + 2).Offset(, 4).Value2 = _
LTrim(Right(AddressField, Len(AddressField) - Len(Left(AddressField, 100)))) & ", " & cell.Offset(, 2).Value2
Sheets("Royal Mail").Range("j" & cell.Row + 2).Value2 = Left(AddressField, 100)
End If
Next