LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Clear a "moving" range offset from Target

Drop Downs in cells B2 & D2 (more to come, maybe 5 + or so).

Code does what I want except the ClearContents which I have commented out.
(Ebable Events is commented out and I am using .Select for testing)

When a selection is made in the drop down, a list pertaining to that selection is copied to the column to the right of the drop down.

I am having trouble clearing that copied list when the next selection is made.
The list are various rows long and the column needs to be clean prior to the next list copied. Can't quite zero in on it, its just me and the late night I suppose!

The Drop Downs will be in every other column in row 2, for however many there will be.

Thanks.
Howard

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B2,D2")) Is Nothing Then Exit Sub

Dim rngFound As Range
Dim aRowCount As Long, _
aColumn As Long, _
tRowCount As Long, _
tColumn As Long

Dim myFnd As String

myFnd = Target

'Application.EnableEvents = False

' tColumn = Target.Offset(, 1).Column
' MsgBox tColumn
' tRowCount = Cells(Rows.Count, tColumn).End(xlUp).Row
' MsgBox tRowCount

' Target.Offset(, 1).Resize(tRowCount, tColumn).Select '.ClearContents
'Exit Sub

Set rngFound = Sheets("Sheet3").Range("AA1:AL1").Find(What:=myFnd , _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not rngFound Is Nothing Then

aColumn = rngFound.Column
aRowCount = Cells(Rows.Count, aColumn).End(xlUp).Row
aColumn = rngFound.Column

rngFound.Offset(1, 0).Resize(aRowCount).Copy Target.Offset(, 1)

Else
MsgBox "No match found."
End If
Application.EnableEvents = True
End Sub

 
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
"ElseIf c.Value = "X_Clear" Then" and "...Target.Cells.Count 1"don't work Howard Excel Programming 4 July 12th 13 02:35 PM
Whats wrong with this? MyWBAccRep.Sheets("Volumes").Cells.Find("latest").Copy.Offset(0, Simon[_2_] Excel Programming 2 August 11th 08 01:29 PM
Clear if "#N/A" and Find End of Range, Fill Blanks ryguy7272 Excel Programming 4 July 23rd 08 01:36 PM
Moving between "row" and "range" formats in VBA kls[_2_] Excel Programming 1 September 11th 04 10:44 PM
SQL "INSERT INTO" Does not Modify Definition of Target Range No Name Excel Programming 0 February 27th 04 10:13 PM


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