VBA Warning - Character Length

neilwakefield

New Member
Joined
Dec 1, 2016
Messages
1
Hi Guys,

I was wondering if someone could help me please?

I have a macro that is imports data from a txt file.

I'm trying to write the VBA that would notify a user via a Message Box/Popup Warning if the characters of a cell exceeded the max limit of 32767, and possibly cell reference the cell in question.

I was previously using the following formula in the Conditional Formatting however as the size of the file has increased a popup warning would be more beneficial no:

=LEN(A1)>32766
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I'm afraid you would have to call a sub that evaluates your range of concern.

Try this code and modify the range to fit your dataset:

Code:
For Each cell In Range("A1:A5")
    If Len(cell.Text) > 32766 Then MsgBox "characters of a cell exceeded the max limit of 32767" & vbCrLf & "CELL ADDRESS: " & cell.Address
Next
 
Last edited:
Upvote 0
If there are multiple cells that exceed the maximum character limit, the following will present a single message box rather than one for each cell. It will also highlight the cells in yellow.

Code:
Sub CharacterLimit()
Dim txt As String
Dim r As Range, rng As Range
Set rng = Range("A1:A5")
For Each r In rng
    If Len(r.Text) > 32766 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

Cheers,

tonyyy
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,738
Members
448,988
Latest member
BB_Unlv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top