Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 21
Default Macro clear cells if meet 1 condition

Hello out the

I have a worksheet (sheet 1) I need to write a macro that will look at
A4:A2500, clear contents of all cells that have a value <140, then look at
column C4:C2500 and clear contents of all cells that have a value 30. I
have more conditions, but can modify the code to meet the requirements.

Would appreciate any assistance on this.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,805
Default Macro clear cells if meet 1 condition

Try
'This will work on the current sheet...
Sub clear()
Range("A4:A2000").Select
For Each CurCell In Selection
If CurCell.Value < 140 Then CurCell.ClearContents
Next CurCell
End Sub
--
Always provide your feedback so that others know whether the solution worked
or problem still persists ...


"Sojo" wrote:

Hello out the

I have a worksheet (sheet 1) I need to write a macro that will look at
A4:A2500, clear contents of all cells that have a value <140, then look at
column C4:C2500 and clear contents of all cells that have a value 30. I
have more conditions, but can modify the code to meet the requirements.

Would appreciate any assistance on this.

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,344
Default Macro clear cells if meet 1 condition

Hi,

Some slightly shorter code:

Sub clear()
For Each cell In Range("A4:A2000").Select
If cell < 140 Then cell.ClearContents
Next cell
End Sub

By the way if this proves slow, there is a faster way to do it. The code is
longer but the execution time is shorter. Maybe as much as 50-100 times
faster. Let us know.
--
Thanks,
Shane Devenshire


"Sheeloo" wrote:

Try
'This will work on the current sheet...
Sub clear()
Range("A4:A2000").Select
For Each CurCell In Selection
If CurCell.Value < 140 Then CurCell.ClearContents
Next CurCell
End Sub
--
Always provide your feedback so that others know whether the solution worked
or problem still persists ...


"Sojo" wrote:

Hello out the

I have a worksheet (sheet 1) I need to write a macro that will look at
A4:A2500, clear contents of all cells that have a value <140, then look at
column C4:C2500 and clear contents of all cells that have a value 30. I
have more conditions, but can modify the code to meet the requirements.

Would appreciate any assistance on this.

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Macro clear cells if meet 1 condition

Shane
.. there is a faster way to do it ..

I'd would like to learn this. If you could ..
Thanks
--
Max
Singapore
http://savefile.com/projects/236895
Downloads:19,000 Files:362 Subscribers:62
xdemechanik
---


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Macro clear cells if meet 1 condition

You left the .select in the code.

I bet you wanted:

Sub clear()
For Each cell In Range("A4:A2000")
If cell < 140 Then cell.ClearContents
Next cell
End Sub

ShaneDevenshire wrote:

Hi,

Some slightly shorter code:

Sub clear()
For Each cell In Range("A4:A2000").Select
If cell < 140 Then cell.ClearContents
Next cell
End Sub

By the way if this proves slow, there is a faster way to do it. The code is
longer but the execution time is shorter. Maybe as much as 50-100 times
faster. Let us know.
--
Thanks,
Shane Devenshire

"Sheeloo" wrote:

Try
'This will work on the current sheet...
Sub clear()
Range("A4:A2000").Select
For Each CurCell In Selection
If CurCell.Value < 140 Then CurCell.ClearContents
Next CurCell
End Sub
--
Always provide your feedback so that others know whether the solution worked
or problem still persists ...


"Sojo" wrote:

Hello out the

I have a worksheet (sheet 1) I need to write a macro that will look at
A4:A2500, clear contents of all cells that have a value <140, then look at
column C4:C2500 and clear contents of all cells that have a value 30. I
have more conditions, but can modify the code to meet the requirements.

Would appreciate any assistance on this.


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 21
Default Macro clear cells if meet 1 condition

That worked perfectly!!! Thank you all so much :-)

"Dave Peterson" wrote:

You left the .select in the code.

I bet you wanted:

Sub clear()
For Each cell In Range("A4:A2000")
If cell < 140 Then cell.ClearContents
Next cell
End Sub

ShaneDevenshire wrote:

Hi,

Some slightly shorter code:

Sub clear()
For Each cell In Range("A4:A2000").Select
If cell < 140 Then cell.ClearContents
Next cell
End Sub

By the way if this proves slow, there is a faster way to do it. The code is
longer but the execution time is shorter. Maybe as much as 50-100 times
faster. Let us know.
--
Thanks,
Shane Devenshire

"Sheeloo" wrote:

Try
'This will work on the current sheet...
Sub clear()
Range("A4:A2000").Select
For Each CurCell In Selection
If CurCell.Value < 140 Then CurCell.ClearContents
Next CurCell
End Sub
--
Always provide your feedback so that others know whether the solution worked
or problem still persists ...


"Sojo" wrote:

Hello out the

I have a worksheet (sheet 1) I need to write a macro that will look at
A4:A2500, clear contents of all cells that have a value <140, then look at
column C4:C2500 and clear contents of all cells that have a value 30. I
have more conditions, but can modify the code to meet the requirements.

Would appreciate any assistance on this.


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Macro clear cells if meet 1 condition

Dave,
I'm not sure if Shane is coming back to this thread

He mentioned earlier:
.. there is a faster way to do it. The code is longer but the execution
time is shorter.
Maybe as much as 50-100 times faster


I'd be interested to learn more about that alternative
If you could ..

Muchas gracias`
Max


  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Macro clear cells if meet 1 condition

I'm not sure what Shane meant.

Maybe he was going to use .specialcells to limit the number of cells to just the
numeric constants???

Dim myRng as range
dim myCell as range
set myrng = nothing
on error resume next
set myrng = somerange.Cells.SpecialCells(xlCellTypeConstants, xlNumbers)
on error goto 0

if myrng is nothing then
msgbox "No numbers"
else
for each mycell in myrng.cells
...
next mycell
end if

But that's just a guess.


Max wrote:

Dave,
I'm not sure if Shane is coming back to this thread

He mentioned earlier:
.. there is a faster way to do it. The code is longer but the execution
time is shorter.
Maybe as much as 50-100 times faster


I'd be interested to learn more about that alternative
If you could ..

Muchas gracias`
Max


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Macro clear cells if meet 1 condition

Thanks for your thoughts, Dave


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
sum cells that meet a specific condition George P Excel Worksheet Functions 1 January 29th 08 03:36 AM
How to only incld cells that meet set condition in an Excel calc? ScottFisher2004 Excel Worksheet Functions 1 March 22nd 07 07:18 PM
macro to clear cells press313 Excel Discussion (Misc queries) 0 May 24th 06 02:31 AM
In excel counting cells in a range which meet condition "Xand<X" Uncivil Servant Excel Worksheet Functions 1 May 19th 06 02:37 PM
sum of a cell if 2 cells meet a condition Markitos Excel Worksheet Functions 4 January 4th 05 05:27 PM


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