vba to check If cell has exactly 1 character in it.

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
Hello all,

How do I check my Active Sheet and Range I3 for number of characters inside of it. If the number of characters are exactly 1 then msgbox the user. "This cell has 1 character."

Thanks and will appreciate.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Len is not a property of a range, rather, it is a built in VBA function that takes a text string as its argument. So...
VBA Code:
If Len(ActiveSheet.Range("I3").Value) = 1 Then
I would note, though, that when not specified, ActiveSheet is the default for a range, so this could be written more compactly like this...
VBA Code:
If Len(Range("I3").Value) = 1 Then
 
Upvote 0
Solution
Len is not a property of a range, rather, it is a built in VBA function that takes a text string as its argument. So...
VBA Code:
If Len(ActiveSheet.Range("I3").Value) = 1 Then
I would note, though, that when not specified, ActiveSheet is the default for a range, so this could be written more compactly like this...
VBA Code:
If Len(Range("I3").Value) = 1 Then

Thanks Rick for explaining the Len and for the compact script.
 
Upvote 0

Forum statistics

Threads
1,213,568
Messages
6,114,348
Members
448,570
Latest member
rik81h

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