Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Clear Contants in a Range Based on a Value

I need to clear constants in a range based on the value of a cell.



The values are 'yes' or 'no' (it is restricted by validation) and stored in
the first row (C1:AR1). If the value is 'no' all constants in the
corresponding column should be cleared from row 9 onward. The number of
rows is variable. A 'yes' value will not require any action.



I am using Excel 2002.



Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Clear Contants in a Range Based on a Value


If this isn't what you are looking for, let me know so I can revise it.

Sub test1()
Dim i As Integer

i = 3
Do While Cells(1, i).Value = "Yes"
i = i + 1

If Cells(1, i).Value = "No" Then
Cells(1, i).Select
Columns(i).Delete
End If
Loop

End Sub


--
dok112
------------------------------------------------------------------------
dok112's Profile: http://www.excelforum.com/member.php...o&userid=10581
View this thread: http://www.excelforum.com/showthread...hreadid=532484

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Clear Contants in a Range Based on a Value

dok112, thank you for the quick reponse. The solution seems to only work
for one column at a time when running the macro i.e., I had to run the macro
once for each column to delete. Should a range of columns be specified?

Also, I am trying to preserve the first 8 rows of data and all formulas in
the column (no matter where they are). Rather than deleteing the whole
column, can the SpecialCells function be used to only delete constants in
the columns from row 9 down. My (ab)users are permitted to add rows and
formulas if necessary.

Thanks


"dok112" wrote in
message ...

If this isn't what you are looking for, let me know so I can revise it.

Sub test1()
Dim i As Integer

i = 3
Do While Cells(1, i).Value = "Yes"
i = i + 1

If Cells(1, i).Value = "No" Then
Cells(1, i).Select
Columns(i).Delete
End If
Loop

End Sub


--
dok112
------------------------------------------------------------------------
dok112's Profile:
http://www.excelforum.com/member.php...o&userid=10581
View this thread: http://www.excelforum.com/showthread...hreadid=532484



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Clear Contants in a Range Based on a Value


Sorry about the delay in not getting back to you. Here is what I came
up with. Let me know if this is what you want it to do...


Sub test()

Dim i As Integer

i = 3

Do While Cells(1, i).Value 0
If Cells(1, i).Value = "Yes" Then
i = i + 1
Else:
Dim cellA As Variant
Dim cellB As Variant
[cellA] = Cells(8, i).Address
[cellB] = Cells(65536, i).Address
Cells(1, i).Select
Range("" & [cellA] & ":" & [cellB] & "").Delete Shift:=xlUp
i = i + 1
End If

Loop

End Sub


--
dok112
------------------------------------------------------------------------
dok112's Profile: http://www.excelforum.com/member.php...o&userid=10581
View this thread: http://www.excelforum.com/showthread...hreadid=532484

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Clear Contants in a Range Based on a Value

That worked great. Thank you. I tweaked it a bit to clear constants as I
had formulas dependant on the cleared cells:

'to clear data only not formulas
Range("" & [cellA] & ":" & [cellB] & "").Select
On Error Resume Next 'to handle no constants in range --
Selection.SpecialCells(xlConstants).ClearContents

Regards,

Jeff



"dok112" wrote in
message ...

Sorry about the delay in not getting back to you. Here is what I came
up with. Let me know if this is what you want it to do...


Sub test()

Dim i As Integer

i = 3

Do While Cells(1, i).Value 0
If Cells(1, i).Value = "Yes" Then
i = i + 1
Else:
Dim cellA As Variant
Dim cellB As Variant
[cellA] = Cells(8, i).Address
[cellB] = Cells(65536, i).Address
Cells(1, i).Select
Range("" & [cellA] & ":" & [cellB] & "").Delete Shift:=xlUp
i = i + 1
End If

Loop

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 cell based on text in opposing column [email protected] Excel Worksheet Functions 2 July 14th 08 04:09 AM
Clear Cell based on event w/o macro? Paul987 Excel Worksheet Functions 2 October 27th 05 08:44 PM
Clear cell based on shading demon42 Excel Programming 1 September 22nd 05 12:56 AM
Delete/clear a cell based on another cells contents jademaddy Excel Programming 2 May 19th 05 06:15 PM
Clear range of cells in different worksheet Tim Kelley Excel Programming 1 December 30th 04 06:54 PM


All times are GMT +1. The time now is 07:07 AM.

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"