dougmarkham
Active Member
- Joined
- Jul 19, 2016
- Messages
- 252
- Office Version
- 365
- Platform
- Windows
Hi Folks,
I have some VBA code that highlights cells which exceed a certain number of characters 'Red'--- until the cell character count drops below the condition, then the cell becomes un-highlighted.
At the end of the VBA I put a message box to inform the user their cells exceed character limits. This message box currently pops up every time there is a change to the cell contents, until all the cells referred to in the code meet the conditions.
What I want this code to do is to activate the pop-up box only once if any of the cells contain more than the permitted characters, so that it's not necessary to keep closing the pop-up box after each amendment. I googled this without success.
Would anybody be able to help me amend this code please?
Kind regards,
Doug.
I have some VBA code that highlights cells which exceed a certain number of characters 'Red'--- until the cell character count drops below the condition, then the cell becomes un-highlighted.
At the end of the VBA I put a message box to inform the user their cells exceed character limits. This message box currently pops up every time there is a change to the cell contents, until all the cells referred to in the code meet the conditions.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)Dim c As Range
Dim LR As Integer
Dim numProbs As Long
Dim sht As Worksheet
Set sht = Worksheets("DX import template")
numProbs = 0
LR = sht.Cells(Rows.Count, "A").End(xlUp).Row
For Each c In Range("A2:A" & LR)
If Len(c.Value) > 12 Then
c.Interior.Color = vbRed
numProbs = numProbs + 1
Else
c.Interior.Color = xlNone
End If
Next
For Each c In Range("B2:B" & LR)
If Len(c.Value) > 20 Then
c.Interior.Color = vbRed
numProbs = numProbs + 1
Else
c.Interior.Color = xlNone
End If
Next
For Each c In Range("C2:C" & LR)
If Len(c.Value) > 50 Then
c.Interior.Color = vbRed
numProbs = numProbs + 1
Else
c.Interior.Color = xlNone
End If
[COLOR=#0000cd][B]If numProbs > 0 Then[/B][/COLOR][COLOR=#0000cd][B] MsgBox "Character limits - Columns: A (12), B (20), C (50) see " & numProbs & " red cells"[/B][/COLOR]
End If
End Sub
What I want this code to do is to activate the pop-up box only once if any of the cells contain more than the permitted characters, so that it's not necessary to keep closing the pop-up box after each amendment. I googled this without success.
Would anybody be able to help me amend this code please?
Kind regards,
Doug.