Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default To clear apostrophes

Hello,
I've used a variation of the following code to clear zeros from a data
range. Some data that I've imported contains a combination of dates, numbers
and text but mysteriously some cells appear blank but on inspection of the
formula bar they contain a solitary apostrophe. I would have thought that the
following code should clear the apostrophes but it doesn't. Could anybody
help please

Sub CleanApostrophe()
Dim rng As Range, cell
Set rng = Range("Datarange2")
For Each cell In rng
If cell.Value = " ' " Then
cell.ClearContents
End If
Next cell
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default To clear apostrophes

Ben,

Try something like the following:

For Each cell In rng
If cell.PrefixCharacter = "'" And _
Len(cell.Value) = 0 And _
cell.HasFormula = False Then
cell.ClearContents
End If
Next cell


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Ben" wrote in message
...
Hello,
I've used a variation of the following code to clear zeros from
a data
range. Some data that I've imported contains a combination of
dates, numbers
and text but mysteriously some cells appear blank but on
inspection of the
formula bar they contain a solitary apostrophe. I would have
thought that the
following code should clear the apostrophes but it doesn't.
Could anybody
help please

Sub CleanApostrophe()
Dim rng As Range, cell
Set rng = Range("Datarange2")
For Each cell In rng
If cell.Value = " ' " Then
cell.ClearContents
End If
Next cell
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default To clear apostrophes

I like to do this:

select the range
edit|replace
what: (leave blank)
with: $$$$$ (some unique string)
replace all

followed by:
edit|replace
what: $$$$$ (that same unique string)
with: (leave blank)
replace all

If you need a macro, record one when you do it manually.

(I bet those apostrophes are left over from a formula that returned "" and you
converted to values???)

Ben wrote:

Hello,
I've used a variation of the following code to clear zeros from a data
range. Some data that I've imported contains a combination of dates, numbers
and text but mysteriously some cells appear blank but on inspection of the
formula bar they contain a solitary apostrophe. I would have thought that the
following code should clear the apostrophes but it doesn't. Could anybody
help please

Sub CleanApostrophe()
Dim rng As Range, cell
Set rng = Range("Datarange2")
For Each cell In rng
If cell.Value = " ' " Then
cell.ClearContents
End If
Next cell
End Sub


--

Dave Peterson
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
Apostrophes in formula bar Joanne New Users to Excel 2 February 26th 08 07:32 PM
apostrophes teepee[_3_] Excel Discussion (Misc queries) 21 February 14th 08 01:05 AM
Apostrophes in Cell Megadrone Excel Worksheet Functions 4 February 22nd 07 01:51 PM
Apostrophes and Sorting [email protected] Excel Discussion (Misc queries) 3 October 23rd 06 02:01 PM
how do i get rid of hidden apostrophes in cells? brokenmonkey Excel Worksheet Functions 4 November 17th 04 01:53 PM


All times are GMT +1. The time now is 05:19 PM.

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

About Us

"It's about Microsoft Excel"