ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   trigering macro (https://www.excelbanter.com/excel-programming/384570-trigering-macro.html)

Rick

trigering macro
 
How do I triger a macro to run when I exit cell "C1"
Macro is to copy "A1:C1" to another sheet in a different book

This is to be repeated each time I exit column "C_", row after row.


Thanks,
Rick

Jay

trigering macro
 
Hi Rick -

Add this code to the worksheet's module.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Column = 4 Or ActiveCell.Column = 2 Then
MsgBox "Exited Column C..." 'replace this line with a call to your other
macro
End If
End Sub
--
Jay


"Rick" wrote:

How do I triger a macro to run when I exit cell "C1"
Macro is to copy "A1:C1" to another sheet in a different book

This is to be repeated each time I exit column "C_", row after row.


Thanks,
Rick


Rick

trigering macro
 
Sorry Jay:
After entering data in col "A1", the msg execiting column "C" appeared.
Rick

"Jay" wrote:

Hi Rick -

Add this code to the worksheet's module.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Column = 4 Or ActiveCell.Column = 2 Then
MsgBox "Exited Column C..." 'replace this line with a call to your other
macro
End If
End Sub
--
Jay


"Rick" wrote:

How do I triger a macro to run when I exit cell "C1"
Macro is to copy "A1:C1" to another sheet in a different book

This is to be repeated each time I exit column "C_", row after row.


Thanks,
Rick


Jay

trigering macro
 
Rick -

Delete previous code and add all of the code below to the worksheet's
module. Let me know how it works; we'll modify it if we have to...

Note 1. Change the terms "YourDesinationWorkBookName.xls" to the actual
name of your desination workbook.

Note 2. Change the terms "YourSheetName" to the actual name of your
desination worksheet.

Note 3. Both the source workbook and the destination workbook must be open.

---------------------------------------------------------------------------------------------
Public startCol As Integer
Public startRow As Long

Private Sub Worksheet_Activate()
startCol = ActiveCell.Column
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Application.ScreenUpdating = False

On Error GoTo errorHandler

Set wb1 = ActiveWorkbook
Set ws1 = ActiveSheet

If (ActiveCell.Column < 3 And startCol = 3) Or _
(ActiveCell.Column < 3 And startCol = 3) Then
Set wb2 = Workbooks("YourDestinationWorkBookName.xls")
Set ws2 = wb2.Worksheets("YourSheetName")
rw = startRow
Range(Cells(rw, 1), Cells(rw, 3)).Copy
wb2.Activate
ws2.Range("A" & ws2.Rows.Count).End(xlUp).Offset(1, 0).Activate
ws2.Paste
End If

ws1.Activate
Application.CutCopyMode = False
Application.ScreenUpdating = True
startCol = ActiveCell.Column
startRow = ActiveCell.Row
Exit Sub

errorHandler:
MsgBox "The destination workbook must be open..."

End Sub

--
Jay


"Rick" wrote:

Sorry Jay:
After entering data in col "A1", the msg execiting column "C" appeared.
Rick

"Jay" wrote:

Hi Rick -

Add this code to the worksheet's module.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Column = 4 Or ActiveCell.Column = 2 Then
MsgBox "Exited Column C..." 'replace this line with a call to your other
macro
End If
End Sub
--
Jay


"Rick" wrote:

How do I triger a macro to run when I exit cell "C1"
Macro is to copy "A1:C1" to another sheet in a different book

This is to be repeated each time I exit column "C_", row after row.


Thanks,
Rick



All times are GMT +1. The time now is 03:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com