Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Search and replace blanks

How do you search an entier spreadsheet and do the following:

1) Check if the contents of a cell is numeric?
2) If content is numeric then search for blanks (" ") and replace them with
nothing (""). E.g. I hace a number in a cell written like: 1000 22 458 but
want to convert it to 100022458. I do not want text like: 'Market value' to
be replaced by 'Marketvalue'.

Please help me on this one!!!
--
I am very thankful for any fast assistance!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Search and replace blanks

Hi Samantha,

Try:

'=============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range

Set WB = Workbooks("YourBook.xls") '<<===== CHANGE
Set SH = WB.Sheets("Sheet1") '<<===== CHANGE
Set rng = SH.Range("A1:D30") '<<===== CHANGE

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
'<<=============

--
---
Regards,
Norman



"SamanthaK" wrote in message
...
How do you search an entier spreadsheet and do the following:

1) Check if the contents of a cell is numeric?
2) If content is numeric then search for blanks (" ") and replace them
with
nothing (""). E.g. I hace a number in a cell written like: 1000 22 458 but
want to convert it to 100022458. I do not want text like: 'Market value'
to
be replaced by 'Marketvalue'.

Please help me on this one!!!
--
I am very thankful for any fast assistance!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Search and replace blanks

Great!! Thanxxx! Is there any way to refer to the entier Worksheet (I want to
check all cells) without writing a large range?
--
I am very thankful for any fast assistance!


"Norman Jones" skrev:

Hi Samantha,

Try:

'=============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range

Set WB = Workbooks("YourBook.xls") '<<===== CHANGE
Set SH = WB.Sheets("Sheet1") '<<===== CHANGE
Set rng = SH.Range("A1:D30") '<<===== CHANGE

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
'<<=============

--
---
Regards,
Norman



"SamanthaK" wrote in message
...
How do you search an entier spreadsheet and do the following:

1) Check if the contents of a cell is numeric?
2) If content is numeric then search for blanks (" ") and replace them
with
nothing (""). E.g. I hace a number in a cell written like: 1000 22 458 but
want to convert it to 100022458. I do not want text like: 'Market value'
to
be replaced by 'Marketvalue'.

Please help me on this one!!!
--
I am very thankful for any fast assistance!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Search and replace blanks

Hmmm I am having another problem. Even cells containing just text are
"trimmed" e.g. market value does become marketvalue. is there any way to
avoid this? Pleaseeeeeeeeee! ;-)
--
I am very thankful for any fast assistance!


"SamanthaK" skrev:

Great!! Thanxxx! Is there any way to refer to the entier Worksheet (I want to
check all cells) without writing a large range?
--
I am very thankful for any fast assistance!


"Norman Jones" skrev:

Hi Samantha,

Try:

'=============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range

Set WB = Workbooks("YourBook.xls") '<<===== CHANGE
Set SH = WB.Sheets("Sheet1") '<<===== CHANGE
Set rng = SH.Range("A1:D30") '<<===== CHANGE

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
'<<=============

--
---
Regards,
Norman



"SamanthaK" wrote in message
...
How do you search an entier spreadsheet and do the following:

1) Check if the contents of a cell is numeric?
2) If content is numeric then search for blanks (" ") and replace them
with
nothing (""). E.g. I hace a number in a cell written like: 1000 22 458 but
want to convert it to 100022458. I do not want text like: 'Market value'
to
be replaced by 'Marketvalue'.

Please help me on this one!!!
--
I am very thankful for any fast assistance!




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Search and replace blanks

Hi Samantha,

Great!! Thanxxx! Is there any way to refer to the entier Worksheet (I want
to
check all cells) without writing a large range?

Change:

Set rng = SH.Range("A1:D30") '<<===== CHANGE


to

Set rng = SH.UsedRange

Hmmm I am having another problem. Even cells containing just text are
"trimmed" e.g. market value does become marketvalue. is there any way to
avoid this? Pleaseeeeeeeeee! ;-)


Change:

If Not .Value Like "*[A-Z]*" Then


to
If Not UCase(.Value) Like "*[A-Z]*" Then

---
Regards,
Norman




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Search and replace blanks

Thank you so much!!!! They both work but when I use

Set rng = SH.UsedRange

instead of writing

Set rng = SH.Range("A1:D30")

the processing time becomes very very long. Why is that?
--
I am very thankful for any fast assistance!


"Norman Jones" skrev:

Hi Samantha,

Great!! Thanxxx! Is there any way to refer to the entier Worksheet (I want
to
check all cells) without writing a large range?

Change:

Set rng = SH.Range("A1:D30") '<<===== CHANGE


to

Set rng = SH.UsedRange

Hmmm I am having another problem. Even cells containing just text are
"trimmed" e.g. market value does become marketvalue. is there any way to
avoid this? Pleaseeeeeeeeee! ;-)


Change:

If Not .Value Like "*[A-Z]*" Then


to
If Not UCase(.Value) Like "*[A-Z]*" Then

---
Regards,
Norman



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Search and replace blanks


Hi
try

Code:
--------------------

Sub test()
Dim r As Range
With CreateObject("VBScript.RegExp")
.Pattern = "^(\d+\s?)+$"
For Each r In Activesheet.UsedRange
If .Test(r.Value) Then r.Value = Val(r.Value)
Next
End With
End Sub
--------------------


SamanthaK Wrote:
How do you search an entier spreadsheet and do the following:

1) Check if the contents of a cell is numeric?
2) If content is numeric then search for blanks (" ") and replace them
with
nothing (""). E.g. I hace a number in a cell written like: 1000 22 458
but
want to convert it to 100022458. I do not want text like: 'Market
value' to
be replaced by 'Marketvalue'.

Please help me on this one!!!
--
I am very thankful for any fast assistance!



--
jindon
------------------------------------------------------------------------
jindon's Profile: http://www.excelforum.com/member.php...o&userid=13135
View this thread: http://www.excelforum.com/showthread...hreadid=552144

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I replace the #DIV/0! with blanks in the cells? wanttolearn Excel Discussion (Misc queries) 5 April 3rd 23 03:46 PM
How to find and replace with blanks or actually delete row Patmarie985 Excel Worksheet Functions 1 November 10th 08 06:31 PM
replace blanks using formula susiecc60 Excel Worksheet Functions 1 March 27th 06 02:16 AM
Need to get rid of 0's and replace with Blanks Intuit Excel Worksheet Functions 3 February 3rd 06 08:55 PM
replace "#DIV/0!" error with blanks Mark B Excel Worksheet Functions 0 June 22nd 05 10:19 AM


All times are GMT +1. The time now is 04:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"