Find + remove blanks if cell contains only numbers

J

Jenni_Sweden

Hi!! I want to search an entire Worksheet and check if cells consists of only
numbers (all numeric). If a cell is only numeric then I want to search the
cell for blanks and remove them. So far I can search and remove blanks but I
cannot discriminate properly bewteen alpha and numeric. Please help me! I am
clueless. My code so far is:

Public Sub findAndRemoveBlanks()
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range

Set WB = Workbooks("Bok2")
Set SH = WB.Sheets("Dimension")
Set rng = SH.Range("A1:p300")

For Each rCell In rng.Cells
With rCell
If Not IsEmpty(.Value) Then
If Not .Value Like "*[A-Z]*" Then
.Replace What:=" ", Replacement:=""
End If
End If
End With
Next rCell

End Sub
 
D

Dave Peterson

Shouldn't this be part of that other thread with the subject:
"Search and replace blanks"

Jenni_Sweden said:
Hi!! I want to search an entire Worksheet and check if cells consists of only
numbers (all numeric). If a cell is only numeric then I want to search the
cell for blanks and remove them. So far I can search and remove blanks but I
cannot discriminate properly bewteen alpha and numeric. Please help me! I am
clueless. My code so far is:

Public Sub findAndRemoveBlanks()
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range

Set WB = Workbooks("Bok2")
Set SH = WB.Sheets("Dimension")
Set rng = SH.Range("A1:p300")

For Each rCell In rng.Cells
With rCell
If Not IsEmpty(.Value) Then
If Not .Value Like "*[A-Z]*" Then
.Replace What:=" ", Replacement:=""
End If
End If
End With
Next rCell

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top