ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find + remove blanks if cell contains only numbers (https://www.excelbanter.com/excel-programming/364345-find-remove-blanks-if-cell-contains-only-numbers.html)

Jenni_Sweden

Find + remove blanks if cell contains only numbers
 
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

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


All times are GMT +1. The time now is 02:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com