Hi all,
I'm somewhat new to macros in Excel and I've been experimenting with a couple of macros but can't quite get what I need. I have three columns (AF, AG, AH) in an Excel sheet that I need to limit with a certain amount of characters (I can't use formulas as the data will be copy pasted) The required character limitations are below;
Column AF - 200 character limit
Column AH - 350 character limit
Column AG - 500 character limit
I was hoping to get an error message for each column that warns the use the character limit has been exceeded but does not truncate the value. I was also looking into trying to get the cell to be highlighted in a different colour but I cannot get my version to work. I've pasted it below but of course it doesn't need to follow this format if you feel there is a better way. It's possible I am missing something obvious as I'm new to macros; this example was only for one column AF and the cell range 9 and 10 just to test but the plan would be to apply it to the three columns (I assume individually would be better) and for say the first 500 cells as a default.
Any help would be appreciated, or if you need anything further please let me know.
I'm somewhat new to macros in Excel and I've been experimenting with a couple of macros but can't quite get what I need. I have three columns (AF, AG, AH) in an Excel sheet that I need to limit with a certain amount of characters (I can't use formulas as the data will be copy pasted) The required character limitations are below;
Column AF - 200 character limit
Column AH - 350 character limit
Column AG - 500 character limit
I was hoping to get an error message for each column that warns the use the character limit has been exceeded but does not truncate the value. I was also looking into trying to get the cell to be highlighted in a different colour but I cannot get my version to work. I've pasted it below but of course it doesn't need to follow this format if you feel there is a better way. It's possible I am missing something obvious as I'm new to macros; this example was only for one column AF and the cell range 9 and 10 just to test but the plan would be to apply it to the three columns (I assume individually would be better) and for say the first 500 cells as a default.
VBA Code:
Sub CharacterLimit()
Dim txt As String
Dim r As Range, rng As Range
Set rng = Range("AF9:AF10")
For Each r In rng
If Len(r.Text) > 200 Then
r.Interior.Color = 65535
txt = txt & vbCrLf & r.Address(0, 0)
End If
Next r
MsgBox "Cell(s) that exceeded character limits: " & vbCrLf & txt
End Sub
Any help would be appreciated, or if you need anything further please let me know.