+ Reply to Thread
Results 1 to 3 of 3

Create a worksheet change event from an addin macro

Hybrid View

  1. #1
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Create a worksheet change event from an addin macro

    A report I have just inherited contains much data that needs to be copied and pasted into another programme. The report is exported from yet another system so is bare xlsx format. I have created an addin where I can run a column delete from the QAT.
    I am trying to implement this code to be able to copy by select and paste into the other programme. This would need to reside in the worksheets module. Is there a way to declare the range from outside the worksheet module or alternatively a way to copy the code into the worksheet module.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim Lrow As Long
    Dim ws As Worksheet
    Dim answer As Integer
    Set ws = Sheets("DocketList NoLinks - Advanced")
    With ws
    Lrow = .Range("a" & Rows.Count).End(xlUp).Row
        If Not Intersect(Target, Range("A1:a" & Lrow)) Is Nothing Then
            Target.Copy
            End If
        
        
    End With
    
    End Sub
    ultimately I would like the target row to be deleted from the worksheet once pasted.

    Help appreciated
    Last edited by nigelog; 04-10-2019 at 12:19 PM.

  2. #2
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: worksheet change event from an addin can target range be set from addin macro??

    found code from davesexcel which needs not to add a new worksheet. Although the Worksheet name is seen in the debugger it errors on line shown. It will complete if adding a new worksheet.
    Sub copySheetModule()
    
    
      Dim DstCmod    As VBIDE.CodeModule
      Dim xLine As Long
      
    
    
      Set DstCmod = ActiveWorkbook.VBProject.VBComponents(ws.Name).CodeModule '''''''''''''''''''''''''''''''''Error here although sees correct ws
      With DstCmod
                  xLine = .CreateEventProc("SelectionChange", "Worksheet")
                xLine = xLine + 1
                .InsertLines xLine, "  Dim Lrow As Long"
                xLine = xLine + 1
                .InsertLines xLine, "  With ActiveSheet"
                xLine = xLine + 1
                .InsertLines xLine, "  Lrow = .Range(""a"" & Rows.Count).End(xlUp).Row"
                xLine = xLine + 1
                .InsertLines xLine, "  If Not Intersect(Target, Range(""A1:a"" & Lrow)) Is Nothing Then"
                xLine = xLine + 1
                .InsertLines xLine, "  Target.Copy"
                xLine = xLine + 1
                .InsertLines xLine, "  End If"
    End With
    End Sub
    Last edited by nigelog; 04-10-2019 at 02:08 PM.

  3. #3
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Create a worksheet change event from an addin macro

    Copies code to worksheet module if changed to
    Set DstCmod = ActiveWorkbook.VBProject.VBComponents("Sheet1").CodeModule

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Worksheet Change Event adding formulas to target range not working
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-08-2017, 05:46 AM
  2. Code to Pass Worksheet Change in Excel Addin
    By Redled89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2015, 04:26 PM
  3. Addin and ActiveWorkbook catch the same event
    By Jibse in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2015, 11:33 AM
  4. [SOLVED] Move worksheet Event macro to PERSONAL or AddIn
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 10-25-2012, 08:34 AM
  5. Macro to save shared addin to personal addin folder
    By MrStyx in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-31-2008, 10:13 AM
  6. How to call userform/sub in Addin from worksheet event
    By RobynC in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-30-2007, 08:01 AM
  7. [SOLVED] Unshimmed Automation Addin and Shimmed COM Addin in same App Domai
    By Brandon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-27-2006, 06:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1