Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default How to write a Clearcontents command in a macro

Hello,

I copied data from an excel worksheet; all this data contains IF formulas.
Then in another column I paste special, as value, and I select the area in
order to delete the blank cells (Go to Special, blank, delete)
Unfortunately the application always says: "no cells found" and I cannot
delete the empty cells in the selection.
I have been told that probably since I have IF functions which may return a
blank
value ("") if a condition is/isn't met, the better route for deleting would
be: For ... Each loop check for Cell.Value="" then ClearContents

My question is: how can I write the instruction above in the macro to make
it work?


Thank you for your help ! Arno

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default How to write a Clearcontents command in a macro

Hi, I tried the following but I get a sintax error

Worksheets("Sheet1").Range("U1:AA5000").Cell.Value ="".ClearContents

Can you help ?

"Arno" wrote:

Hello,

I copied data from an excel worksheet; all this data contains IF formulas.
Then in another column I paste special, as value, and I select the area in
order to delete the blank cells (Go to Special, blank, delete)
Unfortunately the application always says: "no cells found" and I cannot
delete the empty cells in the selection.
I have been told that probably since I have IF functions which may return a
blank
value ("") if a condition is/isn't met, the better route for deleting would
be: For ... Each loop check for Cell.Value="" then ClearContents

My question is: how can I write the instruction above in the macro to make
it work?


Thank you for your help ! Arno

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to write a Clearcontents command in a macro

Try this:
Worksheets("Sheet1").Range("U1:AA5000").ClearConte nts
or
Worksheets("Sheet1").Range("U1:AA5000").Value = ""

Arno wrote:

Hi, I tried the following but I get a sintax error

Worksheets("Sheet1").Range("U1:AA5000").Cell.Value ="".ClearContents

Can you help ?

"Arno" wrote:

Hello,

I copied data from an excel worksheet; all this data contains IF formulas.
Then in another column I paste special, as value, and I select the area in
order to delete the blank cells (Go to Special, blank, delete)
Unfortunately the application always says: "no cells found" and I cannot
delete the empty cells in the selection.
I have been told that probably since I have IF functions which may return a
blank
value ("") if a condition is/isn't met, the better route for deleting would
be: For ... Each loop check for Cell.Value="" then ClearContents

My question is: how can I write the instruction above in the macro to make
it work?


Thank you for your help ! Arno


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default How to write a Clearcontents command in a macro

Maybe this is what you need
If some cells have values and you only want to delete blank cells

Set myrange = Range("U1:AA5000")
For Each c In myrange
If c.Value = "" Then c.Delete Shift:=xlToLeft
Next

Arno,
If Cell. Value = "" ----You can't ClearContents because it has no contents
to clear
Skinman

"Dave Peterson" wrote in message
...
Try this:
Worksheets("Sheet1").Range("U1:AA5000").ClearConte nts
or
Worksheets("Sheet1").Range("U1:AA5000").Value = ""

Arno wrote:

Hi, I tried the following but I get a sintax error

Worksheets("Sheet1").Range("U1:AA5000").Cell.Value ="".ClearContents

Can you help ?

"Arno" wrote:

Hello,

I copied data from an excel worksheet; all this data contains IF
formulas.
Then in another column I paste special, as value, and I select the area
in
order to delete the blank cells (Go to Special, blank, delete)
Unfortunately the application always says: "no cells found" and I
cannot
delete the empty cells in the selection.
I have been told that probably since I have IF functions which may
return a
blank
value ("") if a condition is/isn't met, the better route for deleting
would
be: For ... Each loop check for Cell.Value="" then ClearContents

My question is: how can I write the instruction above in the macro to
make
it work?


Thank you for your help ! Arno


--

Dave Peterson


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to write a Clearcontents command in a macro

You can do this:

activesheet.range("a1").clearcontents
activesheet.range("a1").clearcontents
activesheet.range("a1").clearcontents
activesheet.range("a1").clearcontents
activesheet.range("a1").clearcontents

All 5 lines will run ok. If the cell is empty, then you can still use
..clearcontents against it.

Skinman wrote:

Maybe this is what you need
If some cells have values and you only want to delete blank cells

Set myrange = Range("U1:AA5000")
For Each c In myrange
If c.Value = "" Then c.Delete Shift:=xlToLeft
Next

Arno,
If Cell. Value = "" ----You can't ClearContents because it has no contents
to clear
Skinman

"Dave Peterson" wrote in message
...
Try this:
Worksheets("Sheet1").Range("U1:AA5000").ClearConte nts
or
Worksheets("Sheet1").Range("U1:AA5000").Value = ""

Arno wrote:

Hi, I tried the following but I get a sintax error

Worksheets("Sheet1").Range("U1:AA5000").Cell.Value ="".ClearContents

Can you help ?

"Arno" wrote:

Hello,

I copied data from an excel worksheet; all this data contains IF
formulas.
Then in another column I paste special, as value, and I select the area
in
order to delete the blank cells (Go to Special, blank, delete)
Unfortunately the application always says: "no cells found" and I
cannot
delete the empty cells in the selection.
I have been told that probably since I have IF functions which may
return a
blank
value ("") if a condition is/isn't met, the better route for deleting
would
be: For ... Each loop check for Cell.Value="" then ClearContents

My question is: how can I write the instruction above in the macro to
make
it work?


Thank you for your help ! Arno


--

Dave Peterson


--

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
ClearContents terminating macro - using 2 workbooks Orbitboy Excel Programming 0 June 27th 08 03:28 PM
"ClearContents" command halts code Dave O Excel Discussion (Misc queries) 3 January 10th 08 03:39 PM
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? Daniel Excel Worksheet Functions 1 June 23rd 05 11:38 PM
ClearContents command causes routine to stop Peter Ekstrom Excel Programming 1 April 11th 05 08:55 PM
Write Command Output jaf Excel Programming 0 July 15th 04 10:01 PM


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