Check for leading Chr in cell - VBA solution

stuartgb100

Active Member
Joined
May 10, 2015
Messages
322
Office Version
  1. 2021
Platform
  1. Windows
I'm getting lots of help from the Forum with trying to help a friend with his data (imported into Excel, and messy).
Many thanks.

The main elements have been dealt with, but I need to flag up the cells where problems may still exist.

The 'cleaned up so far data' is in col C, mainly text based.

As a first step, I would like to find a way to flag up any cell where the very first character is neither alphabetic or numerical.

The data in the col C cells should immediately begin with one of those, and not a space, special character, punctuation mark etc.

So, how can I check for this please ?

Regards and thanks.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
How about
Code:
Sub chk()
Dim cl As Range
For Each cl In Range("C2", Range("C" & Rows.Count).End(xlUp))
   If Not cl.Value Like "[0-9,a-z,A-Z]*" Then
      cl.Interior.Color = vbRed
   End If
Next cl
End Sub
 
Upvote 0
Thanks again Fluff.

I modified the code slightly:

Sub Chk_Leading_Character()

Dim cl As Range

With ActiveSheet
' For Each cl In Range("C2", Range("C" & Rows.Count).End(xlUp))
For Each cl In .Range("B2049:B2051")
If Not IsEmpty(cl) Then
If Not cl.Value Like "[0-9,a-z,A-Z]*" Then
cl.Interior.Color = vbRed
End If
End If
Next cl
End With
End Sub

Question please:

Some apparently 'empty' cells cause no problems.
However, some cause a Type Mismatch.

Is Excel 'seeing' something in these problem cells?
 
Upvote 0
Do you have any formulae in those cells?
 
Upvote 0
Shouldn't be, since this was an import of data from an external source into a new workbook.
However, how do I check ?

"If hasformula" ?
 
Upvote 0
Try =isblank(A1) change A1 to one of the problem cells
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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