Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default visual basic excel 2000

Someone in our office used the spacebar to make some cells in a database look
blank when they were not. I discovered this when trying to write a macro to
manipulate the database with code that used the end up/down, etc. command and
was being interrupted by visually blank spaces that were created by the
spacebar.

I am trying to write code to totally clear only the cells which appear to be
blank and not remove the cells with good data.

I tried to select the general area including the data and use an If then
statement to look at the cells in the selection and clear only the ones who's
value = 0. However I don't know the proper code to select the cells that
might equal zero in this Selection or Range. I'm getting error code 13
mismatches, etc.

Help!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default visual basic excel 2000

I think this macro will do what you want....

Sub ClearCellsThatLookBlank()
Dim Cell As Range
For Each Cell In ActiveSheet.UsedRange.Cells
If Len(Cell.Value) 0 And Len(Trim(Cell.Value)) = 0 Then Cell.Clear
Next
End Sub

--
Rick (MVP - Excel)



"JoenMar" wrote in message
...
Someone in our office used the spacebar to make some cells in a database
look
blank when they were not. I discovered this when trying to write a macro
to
manipulate the database with code that used the end up/down, etc. command
and
was being interrupted by visually blank spaces that were created by the
spacebar.

I am trying to write code to totally clear only the cells which appear to
be
blank and not remove the cells with good data.

I tried to select the general area including the data and use an If then
statement to look at the cells in the selection and clear only the ones
who's
value = 0. However I don't know the proper code to select the cells that
might equal zero in this Selection or Range. I'm getting error code 13
mismatches, etc.

Help!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default visual basic excel 2000

Select the cells whose values you want to test, and then run the
following code:

Sub AAA()
Dim R As Range
Dim RR As Range
Set RR = Selection.SpecialCells( _
xlCellTypeConstants, xlTextValues)
For Each RR In R
If Len(Trim(R.Text)) = 0 Then
R.Value = vbNullString
End If
Next RR
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com





On Thu, 20 May 2010 14:03:01 -0700, JoenMar
wrote:

Someone in our office used the spacebar to make some cells in a database look
blank when they were not. I discovered this when trying to write a macro to
manipulate the database with code that used the end up/down, etc. command and
was being interrupted by visually blank spaces that were created by the
spacebar.

I am trying to write code to totally clear only the cells which appear to be
blank and not remove the cells with good data.

I tried to select the general area including the data and use an If then
statement to look at the cells in the selection and clear only the ones who's
value = 0. However I don't know the proper code to select the cells that
might equal zero in this Selection or Range. I'm getting error code 13
mismatches, etc.

Help!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default visual basic excel 2000


For Each RR In R

should be
For Each R In RR

Sorry about that.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com


On Thu, 20 May 2010 16:43:59 -0500, Chip Pearson
wrote:

Select the cells whose values you want to test, and then run the
following code:

Sub AAA()
Dim R As Range
Dim RR As Range
Set RR = Selection.SpecialCells( _
xlCellTypeConstants, xlTextValues)
For Each RR In R
If Len(Trim(R.Text)) = 0 Then
R.Value = vbNullString
End If
Next RR
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com





On Thu, 20 May 2010 14:03:01 -0700, JoenMar
wrote:

Someone in our office used the spacebar to make some cells in a database look
blank when they were not. I discovered this when trying to write a macro to
manipulate the database with code that used the end up/down, etc. command and
was being interrupted by visually blank spaces that were created by the
spacebar.

I am trying to write code to totally clear only the cells which appear to be
blank and not remove the cells with good data.

I tried to select the general area including the data and use an If then
statement to look at the cells in the selection and clear only the ones who's
value = 0. However I don't know the proper code to select the cells that
might equal zero in this Selection or Range. I'm getting error code 13
mismatches, etc.

Help!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default visual basic excel 2000

Try this macro:

Sub RemoveBlanks()
Dim x As Range, Cntr As Long
On Error GoTo RBerr
Cntr = 0
Cells.Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
For Each x In Selection
If Len(Trim(x.Value)) = 0 Then
x.Value = vbNullString
Cntr = Cntr + 1
End If
Next x
MsgBox Cntr & " cells were updated"
Exit Sub
RBerr:
MsgBox Err.Description, , "RemoveBlanks"
End Sub

Hope this helps,

Hutch

"JoenMar" wrote:

Someone in our office used the spacebar to make some cells in a database look
blank when they were not. I discovered this when trying to write a macro to
manipulate the database with code that used the end up/down, etc. command and
was being interrupted by visually blank spaces that were created by the
spacebar.

I am trying to write code to totally clear only the cells which appear to be
blank and not remove the cells with good data.

I tried to select the general area including the data and use an If then
statement to look at the cells in the selection and clear only the ones who's
value = 0. However I don't know the proper code to select the cells that
might equal zero in this Selection or Range. I'm getting error code 13
mismatches, etc.

Help!




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default visual basic excel 2000

(2nd post - not sure it uploaded) Try this macro:

Sub RemoveBlanks()
Dim x As Range, Cntr As Long
On Error GoTo RBerr
Cntr = 0
Cells.Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
For Each x In Selection
If Len(Trim(x.Value)) = 0 Then
x.Value = vbNullString
Cntr = Cntr + 1
End If
Next x
MsgBox Cntr & " cells were updated"
Exit Sub
RBerr:
MsgBox Err.Description, , "RemoveBlanks"
End Sub

Hope this helps,

Hutch

"JoenMar" wrote:

Someone in our office used the spacebar to make some cells in a database look
blank when they were not. I discovered this when trying to write a macro to
manipulate the database with code that used the end up/down, etc. command and
was being interrupted by visually blank spaces that were created by the
spacebar.

I am trying to write code to totally clear only the cells which appear to be
blank and not remove the cells with good data.

I tried to select the general area including the data and use an If then
statement to look at the cells in the selection and clear only the ones who's
value = 0. However I don't know the proper code to select the cells that
might equal zero in this Selection or Range. I'm getting error code 13
mismatches, etc.

Help!


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default visual basic excel 2000

Instead of looping through all the cells in the worksheet, I think I'd just do a
few edit|Replaces.
But you'll have to decide if the users aren't really out to get you.

Option Explicit
Sub testme()
Dim myRng As Range
Dim iCtr As Long
Dim MaxSpacesToFix As Long

MaxSpacesToFix = 10

With Worksheets("Sheet1")
Set myRng = .Cells 'or some specific range like .Range("A1:X99")
End With

For iCtr = 1 To MaxSpacesToFix
myRng.Replace what:=Space(iCtr), _
replacement:="", _
lookat:=xlWhole, _
searchorder:=xlNext, _
MatchCase:=False
Next iCtr

End Sub

Adjust the maxspacestofix to what you know(?) it can't exceed.

If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)



JoenMar wrote:

Someone in our office used the spacebar to make some cells in a database look
blank when they were not. I discovered this when trying to write a macro to
manipulate the database with code that used the end up/down, etc. command and
was being interrupted by visually blank spaces that were created by the
spacebar.

I am trying to write code to totally clear only the cells which appear to be
blank and not remove the cells with good data.

I tried to select the general area including the data and use an If then
statement to look at the cells in the selection and clear only the ones who's
value = 0. However I don't know the proper code to select the cells that
might equal zero in this Selection or Range. I'm getting error code 13
mismatches, etc.

Help!


--

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
Microsoft Visual Basic UserForm 2 columns, Excel 2000 & 2003 jfcby Excel Programming 1 April 22nd 08 12:19 PM
Excel 2000/Visual Basic -- I need to learn... CMIConnie Excel Discussion (Misc queries) 4 July 10th 06 07:26 PM
Can I run Visual Basic procedure using Excel Visual Basic editor? john.jacobs71[_2_] Excel Programming 3 December 26th 05 02:22 PM
Excel 2000 Visual Basic - Export Contents of ListBox into a worksh Ligaya Excel Programming 7 November 2nd 04 03:58 PM
Addin for Excel 2000/97 (In Visual Basic) Jason Sholar Excel Programming 3 January 29th 04 01:52 PM


All times are GMT +1. The time now is 01:41 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"