Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Clear Contents of Adjacent Cell on Conditional Basis

I want to clear the contents of certain cells if other data on the
same line meets my criteria. For instance, if cell V8=1, I want to
clear the contents (not delete) of cell M8.

I have some code that gets close, but doesn't quite get me what I
want. I have tried to tinker with it, but to no avail.

------------------------------------------------------------------

Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
Firstrow = ActiveSheet.UsedRange.Cells(8).Row
Lastrow = ActiveSheet.UsedRange.Rows.Count + Firstrow - 1
With ActiveSheet
.DisplayPageBreaks = False
For Lrow = Lastrow To Firstrow Step -1
If IsError(.Cells(Lrow, "V").Value) Then
ElseIf .Cells(Lrow, "V").Value = "1"
Then .Rows(Lrow).Delete

'''''''''''''''''' .Rows(Lrow).Delete should be replaced
with something that
tells it to clear contents of the cell in column
M that corresponds
to a value of 1 in column V

End If
Next
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

------------------------------------------------------------------

As always, any help on this issue would be much appreciated. Thanks!

Kevin

  #2   Report Post  
Posted to microsoft.public.excel.misc
Ian Ian is offline
external usenet poster
 
Posts: 238
Default Clear Contents of Adjacent Cell on Conditional Basis

What do you mean by clear but not delete. They are essentially the same.
Either the data is there, or it isn't.

One option might be to change the font colour in the cell to match the
background.

Assuming the font colour option is useful and that column V is the one you
are comparing to in each case, then you could use conditional formatting
instead of code.
--
Ian
--
"DoooWhat" wrote in message
oups.com...
I want to clear the contents of certain cells if other data on the
same line meets my criteria. For instance, if cell V8=1, I want to
clear the contents (not delete) of cell M8.

I have some code that gets close, but doesn't quite get me what I
want. I have tried to tinker with it, but to no avail.

------------------------------------------------------------------

Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
Firstrow = ActiveSheet.UsedRange.Cells(8).Row
Lastrow = ActiveSheet.UsedRange.Rows.Count + Firstrow - 1
With ActiveSheet
.DisplayPageBreaks = False
For Lrow = Lastrow To Firstrow Step -1
If IsError(.Cells(Lrow, "V").Value) Then
ElseIf .Cells(Lrow, "V").Value = "1"
Then .Rows(Lrow).Delete

'''''''''''''''''' .Rows(Lrow).Delete should be replaced
with something that
tells it to clear contents of the cell in column
M that corresponds
to a value of 1 in column V

End If
Next
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

------------------------------------------------------------------

As always, any help on this issue would be much appreciated. Thanks!

Kevin



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Clear Contents of Adjacent Cell on Conditional Basis

Look at:

Sub marine()

Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row - 1
nFirstRow = r.Row

For i = nFirstRow To nLastRow
If Cells(i, "V").Value = 1 Then
Cells(i, "M").Clear
End If
Next
End Sub


--
Gary''s Student
gsnu200709


"DoooWhat" wrote:

I want to clear the contents of certain cells if other data on the
same line meets my criteria. For instance, if cell V8=1, I want to
clear the contents (not delete) of cell M8.

I have some code that gets close, but doesn't quite get me what I
want. I have tried to tinker with it, but to no avail.

------------------------------------------------------------------

Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
Firstrow = ActiveSheet.UsedRange.Cells(8).Row
Lastrow = ActiveSheet.UsedRange.Rows.Count + Firstrow - 1
With ActiveSheet
.DisplayPageBreaks = False
For Lrow = Lastrow To Firstrow Step -1
If IsError(.Cells(Lrow, "V").Value) Then
ElseIf .Cells(Lrow, "V").Value = "1"
Then .Rows(Lrow).Delete

'''''''''''''''''' .Rows(Lrow).Delete should be replaced
with something that
tells it to clear contents of the cell in column
M that corresponds
to a value of 1 in column V

End If
Next
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

------------------------------------------------------------------

As always, any help on this issue would be much appreciated. Thanks!

Kevin


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Clear Contents of Adjacent Cell on Conditional Basis

Ian:

The reason I say "clear contents" instead of "delete" is that deleting
a cell typically moves cells around (shift cells up, left, etc). I'm
speaking of the situation when you can either select a cell and hit
the DELETE button, or you can right click on a cell and click delete.
Right clicking will ask you how you want to shift the cells. Clicking
delete simply clears the contents.

My purpose is to get rid of the data for calculation purposes, not for
viewing, so conditional formatting will not help me (in this case).

Kevin

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Clear Contents of Adjacent Cell on Conditional Basis

Bingo! Thanks so much. Gary would be proud.

You guys rock.

Kevin



  #6   Report Post  
Posted to microsoft.public.excel.misc
Ian Ian is offline
external usenet poster
 
Posts: 238
Default Clear Contents of Adjacent Cell on Conditional Basis

Replace .Rows(Lrow).Delete with .Cells(Lrow, "M").Value = ""

--
Ian
--
"DoooWhat" wrote in message
ups.com...
Ian:

The reason I say "clear contents" instead of "delete" is that deleting
a cell typically moves cells around (shift cells up, left, etc). I'm
speaking of the situation when you can either select a cell and hit
the DELETE button, or you can right click on a cell and click delete.
Right clicking will ask you how you want to shift the cells. Clicking
delete simply clears the contents.

My purpose is to get rid of the data for calculation purposes, not for
viewing, so conditional formatting will not help me (in this case).

Kevin



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Clear Contents of Adjacent Cell on Conditional Basis

If you only wanted to clear the contents (not the formatting), then this:

Cells(i, "M").Clear
would be:
Cells(i, "M").ClearContents



DoooWhat wrote:

Bingo! Thanks so much. Gary would be proud.

You guys rock.

Kevin


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Clear Contents of Adjacent Cell on Conditional Basis

Thanks Ian. That method also worked. I appreciate the quick and
effective response from both of you.

Kevin

  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Clear Contents of Adjacent Cell on Conditional Basis

Hmmm. I'll make a note of that, as it may help me sometime down the
road. Thanks for the tip.

Kevin

On Mar 7, 9:32 am, Dave Peterson wrote:
If you only wanted to clear the contents (not the formatting), then this:

Cells(i, "M").Clear
would be:
Cells(i, "M").ClearContents


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
Is there a formula to clear the contents of a specific cell? Bob Smith Excel Worksheet Functions 2 December 9th 06 07:41 PM
Delete cell contents with input to adjacent cell Ashley Frank Excel Discussion (Misc queries) 1 October 5th 05 04:28 PM
Contents of adjacent cell from a function Nick Excel Worksheet Functions 5 July 8th 05 04:28 PM
vb to clear cell contents RichT New Users to Excel 6 June 27th 05 08:26 AM
Clear cell contents with a button KFC / A&W Boy Excel Worksheet Functions 1 March 7th 05 09:39 AM


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