Code Help

W

Woodi2

Hi, I have a sheet that contains several columns of data. If a user select
any cell in C7 to C10000 then userform 12 opens. I use the following code
for this and this part of the sheet works fine, althoug I dont fully
understand it.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Target, Range("c4:c100")) Is Nothing Then
UserForm12.Show
End If
End Sub

The problem lies with this, I have another code that copies rows 4 to 7 then
finds the last row used in column 'U', activates offset cell (1, -16),
selects the activeCell.entire row and pastes the copied data. Each time I
run this code, Userform 12 is activated whenever rows 4 to 7 are selected, or
any row for that matter because a cell in column 'C' has been activated.

I have tried adding Userform12.hide, ive also made a command button that can
cancel the userform and made this public and select and activate it using
code but to no avail.
I have pasted the code below for what I have tried. In a nutshell, i need
to close userform 12 when it has been activated.


If Rows("4:6").Select Then
UserForm12.CommandButton3.SetFocus
UserForm12.CommandButton3_Click
End If
Selection.Copy
Range("u7").Select
Range("u7").End(xlDown).Select
ActiveCell.Offset(1, -16).Select
ActiveCell.EntireRow.Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C7:C42").Select
Selection.Sort Key1:=Range("C4"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("h2").Select
Unload Me
End Sub
 
J

Jacob Skaria

Try setting Enable Events to False at the top of the procedure and set that
back to True before End Sub

Application.EnableEvents = False

'<your code>

Application.EnableEvents = True
End Sub
 
W

Woodi2

Thanks Jacob. I cannot believe I have been tearing my hair out and it was
that simple. Every day is a school day!
Thanks
Ian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top