#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Code Help

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Code Help

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

--
If this post helps click Yes
---------------
Jacob Skaria


"Woodi2" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Code Help

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

"Jacob Skaria" wrote:

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

--
If this post helps click Yes
---------------
Jacob Skaria


"Woodi2" wrote:

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

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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Run VBA code only worksheet change, but don't trigger worksheet_change event based on what the code does ker_01 Excel Programming 6 October 3rd 08 09:45 PM
Shorten code to apply to all sheets except a few, instead of individually naming them, and later adding to code. Corey Excel Programming 3 December 11th 06 05:14 AM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
Excel code convert to Access code - Concat & eliminate duplicates italia Excel Programming 1 September 12th 06 12:14 AM


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