View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Find + remove blanks if cell contains only numbers

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

Jenni_Sweden wrote:

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


--

Dave Peterson