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

beartooth91

Board Regular
Joined
Dec 15, 2024
Messages
64
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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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
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
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
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
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,225,623
Messages
6,186,065
Members
453,336
Latest member
Excelnoob223

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