VBA Error - "Unable to get the Count property of the Characters class"

beartooth91

Board Regular
Joined
Dec 15, 2024
Messages
69
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Trying to count characters in each cell and flag entries with more than 20 characters. Its failing on the "Unable to get the Count property of the Characters class" error because the string contains numbers (Ex: 0-FHP-CE-0001A). Looking for a SIMPLE fix to be able to count these entries......

VBA Code:
'Missing/Improper Component Number
  For Each cell In .Range("B11:B" & lastRow)
    'cell.NumberFormat = "@"
    If cell.Value = "" Or _
       cell.Characters.Count > 20 Then
       cell.Interior.ColorIndex = 22
    End If
  Next cell
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try
VBA Code:
'Missing/Improper Component Number
  For Each cell In .Range("B11:B" & lastRow)
    'cell.NumberFormat = "@"
    If cell.Value = "" Or _
       Len(cell) > 20 Then
       cell.Interior.ColorIndex = 22
    End If
  Next cell
 
Upvote 0
Solution
Using Len seems to fix my problem......


VBA Code:
'Missing/Improper Component Number
  For Each cell In .Range("B11:B" & lastRow)
    If cell.Value = "" Or _
       Len(cell) > 20 Then
       cell.Interior.ColorIndex = 22
    End If
  Next cell
 
Upvote 0
Yeah, I figured it out and we both posted at the same time. Thanks!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,226,453
Messages
6,191,136
Members
453,642
Latest member
jefals

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