Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Clear corresponding cells in other worksheet

Hello -

Need a little help...

When the user deletes data from a cell in one worksheet, I need to clear a
range in another worksheet that corresponds to the row where the cell was
deleted.

Below is the code I'm using now in worksheet "Worksheet1". When A:"row
number" is cleared by the user in worksheet "Worksheet1", it will clear the
rest of that line. I need to add to this so when the cell is cleared, it
also clears the range F:"row number" from the "Worksheet2" worksheet.

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

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngAllParentCells As Range
Dim rngDepCells As Range
Dim rngCell As Range

Set rngAllParentCells = Range("A6:A51")
Set rngDepCells = Intersect(Target, rngAllParentCells)

Application.ScreenUpdating = False

If Not rngDepCells Is Nothing Then
For Each rngCell In rngDepCells.Cells
rngCell.Offset(RowOffset:=0, ColumnOffset:=1).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=2).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=3).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=4).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=5).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=6).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=7).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=8).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=9).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=10).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=11).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=12).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=13).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=14).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=15).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=16).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=17).ClearContents
Next rngCell
End If
Set rngAllParentCells = Nothing
Set rngDepCells = Nothing
Set rngCell = Nothing

End Sub

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

Since it's using a variable to identify the row and column, I'm not sure how
to identify the corresponding row and column in the other workbook.

Any help appreciated - THANKS!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Clear corresponding cells in other worksheet

Simple

In the for loop get the row of
Myrow = rngCell.row
Worksheets("Sheet2").Rows(Myrow).ClearContents


"Shelly" wrote:

Hello -

Need a little help...

When the user deletes data from a cell in one worksheet, I need to clear a
range in another worksheet that corresponds to the row where the cell was
deleted.

Below is the code I'm using now in worksheet "Worksheet1". When A:"row
number" is cleared by the user in worksheet "Worksheet1", it will clear the
rest of that line. I need to add to this so when the cell is cleared, it
also clears the range F:"row number" from the "Worksheet2" worksheet.

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

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngAllParentCells As Range
Dim rngDepCells As Range
Dim rngCell As Range

Set rngAllParentCells = Range("A6:A51")
Set rngDepCells = Intersect(Target, rngAllParentCells)

Application.ScreenUpdating = False

If Not rngDepCells Is Nothing Then
For Each rngCell In rngDepCells.Cells
rngCell.Offset(RowOffset:=0, ColumnOffset:=1).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=2).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=3).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=4).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=5).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=6).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=7).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=8).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=9).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=10).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=11).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=12).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=13).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=14).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=15).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=16).ClearContents
rngCell.Offset(RowOffset:=0, ColumnOffset:=17).ClearContents
Next rngCell
End If
Set rngAllParentCells = Nothing
Set rngDepCells = Nothing
Set rngCell = Nothing

End Sub

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

Since it's using a variable to identify the row and column, I'm not sure how
to identify the corresponding row and column in the other workbook.

Any help appreciated - THANKS!

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
How to clear all filters in worksheet for all columns Helios Excel Discussion (Misc queries) 2 November 11th 07 11:19 PM
clear contents cells of unprotected cells Ed Excel Programming 6 January 12th 06 06:09 PM
Clear cells range if certain cells are all empty gschimek - ExcelForums.com Excel Programming 6 May 13th 05 10:38 PM
Clear range of cells in different worksheet Tim Kelley Excel Programming 1 December 30th 04 06:54 PM
Clear the content of a worksheet using VBA Shawshank Excel Programming 3 January 13th 04 03:47 PM


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