Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Clear Contents of multiple continuous ranges

Hi all,
I am trying to clear the content of certain cells in my worksheet only if
certain criteria is met. For Example,
If C5=Delete I want the following range cleared (G3:H3,K3:L3, H5:K7,M5:O7
If C12=Delete I want the following range
cleared(G10:H10,K10:M10,H12:K14,M12:O14)
and so on

Dont know if this will help but,
there is some relationship of 6 cells in between one range and the other
(from C5 to C12 there're 6 cells (that I want to remain untouch) from C12 and
C19 there are 6 cells and so on. The same with the range I want to be
cleared
From G3 to G10 there are 6 cells (that I want to reamin untouch)

This is what I have: but is not working (there's no changes on my worksheet)
-----------------------------------------
Dim x As Long
Dim lastrow As Long

Application.ScreenUpdating = False

lastrow = Range("A65536").End(xlUp).Row

For x = 5 To lastrow
If Cells(x, 3) = "Delete" Then
Range("G3:H3, K3:L3, H5:K7,M5:O7, G10:H10, K10:M10, H12:K12,
M12:O12").ClearContents
Application.ScreenUpdating = True
End If
Next x

End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Clear Contents of multiple continuous ranges

I'd try:

Option Explicit
Sub testme()

Dim iRow As Long
Dim LastRow As Long
Dim wks As Worksheet

Set wks = ActiveSheet

Application.ScreenUpdating = False

With wks
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = 5 To LastRow
If LCase(.Cells(iRow, 3).Value) = LCase("Delete") Then
.Cells(iRow - 4, 1).Range("G3:H3,K3:L3," _
& "H5:K7,M5:O7,G10:H10,K10:M10,H12:K12,M12:O12") _
.ClearContents
End If
Next iRow
End With

Application.ScreenUpdating = True

End Sub



Mlawrence wrote:

Hi all,
I am trying to clear the content of certain cells in my worksheet only if
certain criteria is met. For Example,
If C5=Delete I want the following range cleared (G3:H3,K3:L3, H5:K7,M5:O7
If C12=Delete I want the following range
cleared(G10:H10,K10:M10,H12:K14,M12:O14)
and so on

Dont know if this will help but,
there is some relationship of 6 cells in between one range and the other
(from C5 to C12 there're 6 cells (that I want to remain untouch) from C12 and
C19 there are 6 cells and so on. The same with the range I want to be
cleared
From G3 to G10 there are 6 cells (that I want to reamin untouch)

This is what I have: but is not working (there's no changes on my worksheet)
-----------------------------------------
Dim x As Long
Dim lastrow As Long

Application.ScreenUpdating = False

lastrow = Range("A65536").End(xlUp).Row

For x = 5 To lastrow
If Cells(x, 3) = "Delete" Then
Range("G3:H3, K3:L3, H5:K7,M5:O7, G10:H10, K10:M10, H12:K12,
M12:O12").ClearContents
Application.ScreenUpdating = True
End If
Next x

End Sub



--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 419
Default Clear Contents of multiple continuous ranges

Mlawrence,

You have "Application.ScreenUpdating = False" first thing, outside of the if
statement, turning it off. Then you have "Application.ScreenUpdating =
True" inside of the if statement turning it on.

Screen Updating will always be turned off, but it will only be turned on
when the test in the if statement is true. IMO, that is not good practice.
There could be times when it is turned off and left off.

I know that probably does not fix your problem. I just wanted to draw your
attention to it for future reference.

HTH,

Conan




"Mlawrence" wrote in message
...
Hi all,
I am trying to clear the content of certain cells in my worksheet only if
certain criteria is met. For Example,
If C5=Delete I want the following range cleared (G3:H3,K3:L3, H5:K7,M5:O7
If C12=Delete I want the following range
cleared(G10:H10,K10:M10,H12:K14,M12:O14)
and so on

Dont know if this will help but,
there is some relationship of 6 cells in between one range and the other
(from C5 to C12 there're 6 cells (that I want to remain untouch) from C12
and
C19 there are 6 cells and so on. The same with the range I want to be
cleared
From G3 to G10 there are 6 cells (that I want to reamin untouch)

This is what I have: but is not working (there's no changes on my
worksheet)
-----------------------------------------
Dim x As Long
Dim lastrow As Long

Application.ScreenUpdating = False

lastrow = Range("A65536").End(xlUp).Row

For x = 5 To lastrow
If Cells(x, 3) = "Delete" Then
Range("G3:H3, K3:L3, H5:K7,M5:O7, G10:H10, K10:M10, H12:K12,
M12:O12").ClearContents
Application.ScreenUpdating = True
End If
Next x

End Sub





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
clear contents Arne Hegefors Excel Programming 1 June 13th 07 03:39 PM
Macro to clear range contents when cell contents are changed by us Steve E Excel Programming 12 February 22nd 07 09:09 PM
Clear contents Arne Hegefors Excel Programming 3 September 28th 06 05:43 PM
Clear contents SamanthaK Excel Programming 3 June 15th 06 09:05 AM
Clear Contents Help michael Excel Programming 3 June 6th 06 09:42 PM


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