Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 159
Default Help with combining/merging code

I have one sortting code that is attached to a worksheet change event and
another in a button click event and I want to merge the worksheet change code
into the button click event code or what ever else can be suggested.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

End Sub
Const WS_RANGE As String = "B2:B5001"

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Me.Cells(.Row, "A").Value = WorksheetFunction.Max(Range("A1:A5001")) + 1
Me.Range("A:G").Sort key1:=Me.Range("B3"), header:=xlYes
End With
End If

ws_exit:
Application.EnableEvents = True

End Sub


Private Sub BtnDelete_Click()
Dim fRow As Long

On Error GoTo ender
fRow = Columns(2).Find(What:=TxtMan.Value, _
After:=Cells(5000, 2), LookIn:=xlFormulas, _
LookAT:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, _
SearchFormat:=False).Row
Rows(fRow).Delete
Exit Sub

ws_exit:
Application.EnableEvents = True
Exit Sub
ender:
MsgBox "Value not found"
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Help with combining/merging code

I am not sure if this applies to you, but in general:

1. The button code should disable events until it is done
2. If the button code and worksheet code need to call a common sub, then the
common sub should be declared Public in a standard module.
--
Gary''s Student - gsnu200749


"Mekinnik" wrote:

I have one sortting code that is attached to a worksheet change event and
another in a button click event and I want to merge the worksheet change code
into the button click event code or what ever else can be suggested.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

End Sub
Const WS_RANGE As String = "B2:B5001"

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Me.Cells(.Row, "A").Value = WorksheetFunction.Max(Range("A1:A5001")) + 1
Me.Range("A:G").Sort key1:=Me.Range("B3"), header:=xlYes
End With
End If

ws_exit:
Application.EnableEvents = True

End Sub


Private Sub BtnDelete_Click()
Dim fRow As Long

On Error GoTo ender
fRow = Columns(2).Find(What:=TxtMan.Value, _
After:=Cells(5000, 2), LookIn:=xlFormulas, _
LookAT:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, _
SearchFormat:=False).Row
Rows(fRow).Delete
Exit Sub

ws_exit:
Application.EnableEvents = True
Exit Sub
ender:
MsgBox "Value not found"
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
Merging and combining two reports Matthew G Excel Discussion (Misc queries) 3 January 8th 09 03:34 PM
Merging/Combining workbook data Gemi Excel Discussion (Misc queries) 5 November 25th 08 05:15 PM
Combining and merging lines Dawn Excel Discussion (Misc queries) 1 January 3rd 08 03:44 PM
Combining/Merging Rows Grace[_2_] Excel Discussion (Misc queries) 1 October 10th 07 01:03 AM
Combining Excel files into 1 (no merging) Margo New Users to Excel 1 July 24th 07 03:57 PM


All times are GMT +1. The time now is 05:25 AM.

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"