+ Reply to Thread
Results 1 to 11 of 11

Call Private Sub Worksheet_Change

Hybrid View

BrianAll Call Private Sub... 02-05-2019, 08:35 AM
Olly Re: Call Private Sub... 02-05-2019, 08:43 AM
dotchiejack Re: Call Private Sub... 02-05-2019, 08:46 AM
KOKOSEK Re: Call Private Sub... 02-05-2019, 08:53 AM
dotchiejack Re: Call Private Sub... 02-05-2019, 08:56 AM
KOKOSEK Re: Call Private Sub... 02-05-2019, 11:37 AM
BrianAll Re: Call Private Sub... 02-05-2019, 04:48 PM
YasserKhalil Re: Call Private Sub... 02-05-2019, 09:04 AM
YasserKhalil Re: Call Private Sub... 02-05-2019, 11:44 PM
jindon Re: Call Private Sub... 02-06-2019, 12:21 AM
BrianAll Re: Call Private Sub... 02-06-2019, 06:18 AM
  1. #1
    Registered User
    Join Date
    06-19-2013
    Location
    Sheffield
    MS-Off Ver
    Excel 2013
    Posts
    86

    Call Private Sub Worksheet_Change

    Hello,

    I need to call from Macro1 in Module 1 the "Private Sub Worksheet_Change(ByVal Target As Range)".
    I tried with:
    Application.Run "Sheet1.Worksheet_Change"
    but it doesn't work.

    Any help?

    Thanks!

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Call Private Sub Worksheet_Change

    Put your code in a separate subroutine. Call that subroutine from both the worksheet change event, and from Macro 1.

    e.g.

    Private Sub Worksheet_Change(ByVal Target As Range)
        Call foo
    End Sub
    
    Sub foo()
        'your code here
        Debug.Print "foo happened"
    End Sub
    
    Sub Macro1()
        Call foo
    End Sub
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Valued Forum Contributor dotchiejack's Avatar
    Join Date
    05-21-2015
    Location
    Antwerp,Belgium
    MS-Off Ver
    2016
    Posts
    507

    Re: Call Private Sub Worksheet_Change

    I need to call from Macro1 in Module 1 the "Private Sub Worksheet_Change(ByVal Target As Range)".
    This is not possible.
    post your Worksheet change code so that helpers can change it to work in a module.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,765

    Re: Call Private Sub Worksheet_Change

    Private Sub Worksheet_Change(ByVal Target As Range)
        Call macro1
    End Sub
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  5. #5
    Valued Forum Contributor dotchiejack's Avatar
    Join Date
    05-21-2015
    Location
    Antwerp,Belgium
    MS-Off Ver
    2016
    Posts
    507

    Re: Call Private Sub Worksheet_Change

    When I read the question I think TS wants the opposite.
    Sub macro1
    Call Worksheet_Change
    end sub
    this is not possible

  6. #6
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,765

    Re: Call Private Sub Worksheet_Change

    Quote Originally Posted by dotchiejack View Post
    When I read the question I think TS wants the opposite.
    Sub macro1
    Call Worksheet_Change
    end sub
    this is not possible
    You right. Sorry.
    I can't get idea of that. What kind of results is expected?
    Last edited by KOKOSEK; 02-05-2019 at 11:40 AM.

  7. #7
    Registered User
    Join Date
    06-19-2013
    Location
    Sheffield
    MS-Off Ver
    Excel 2013
    Posts
    86

    Re: Call Private Sub Worksheet_Change

    Hello,

    well, Macro 1 checks if all the column headers have an expected value "string".
    If not, an error MsgBox is shown.
    If an error is found I want to give the user to correct the wrong column header name.
    I can do it with
    Application.wait
    but this doesn't allow the user to type on the Sheet.
    The best solution would be:
    - Error Found
    - MsgBox Shown
    - Let the user type on the Sheet to correct the mistake
    - The Worksheet "recognize" the Change through
    Private Sub Worksheet_Change(ByVal Target As Range)
    - The check routine (
    Go to ControllaColonne
    ) is performed again.



    Sub Macro1()
    
    Dim ArrayTitoli(13) As String
    Dim Result As Integer
        
    '   Declare Array with correct column headers
        ArrayTitoli(0) = "Anno Stagione"
        ArrayTitoli(1) = "Tema"
        ArrayTitoli(2) = "Fase di Nascita cod"
        ArrayTitoli(3) = "Classe"
        ArrayTitoli(4) = "Articolo"
        ArrayTitoli(5) = "Colore"
        ArrayTitoli(6) = "Quantità"
        ArrayTitoli(7) = "0 - DA RICEVERE"
        ArrayTitoli(8) = "1 - DA LANCIARE"
        ArrayTitoli(9) = "2 - TAGLIO"
        ArrayTitoli(10) = "3 - PREPARAZIONE"
        ArrayTitoli(11) = "4 - ASSEMBLAGGIO"
        ArrayTitoli(12) = "5 - RIFINITURE"
        ArrayTitoli(13) = "CHIUSE"
    
        
    ControllaColonne:
        For i = 0 To 13
        With Range("A1")
            If .Offset(0, i) <> ArrayTitoli(i) Then
            Result = MsgBox("Verificare che i titoli corrispondano all'estrazione corretta." _
            & Chr(13) & "L'ordine corretto è il seguente:" _
            & Chr(13) & "" _
            & Chr(13) & "Anno Stagione" _
            & Chr(13) & "Tema" _
            & Chr(13) & "Fase di Nascita cod" _
            & Chr(13) & "Classe" _
            & Chr(13) & "Articolo" _
            & Chr(13) & "Colore" _
            & Chr(13) & "Quantità" _
            & Chr(13) & "0 - DA RICEVERE" _
            & Chr(13) & "1 - DA LANCIARE" _
            & Chr(13) & "2 - TAGLIO" _
            & Chr(13) & "3 - PREPARAZIONE" _
            & Chr(13) & "4 - ASSEMBLAGGIO" _
            & Chr(13) & "5 - RIFINITURE" _
            & Chr(13) & "CHIUSE" _
            & Chr(13) _
            & Chr(13) & "Errore nell colonna: " & i + 1 & ".", vbCritical, "Colonne non Corrispondenti")
            End If
        End With
        Next
        
        
    '   ****PROBLEM****
        If Result > 0 Then
        Application.Run "Sheet1.Worksheet_Change", Range("A1")
        'Application.Wait (Now + TimeValue("0:00:10"))
        'GoTo ControllaColonne
        End If
    
    End Sub
    Thanks!

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Call Private Sub Worksheet_Change

    Try this
    Sub Test()
        Application.Run "Sheet1.Worksheet_Change", Range("A1")
    End Sub
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  9. #9
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Call Private Sub Worksheet_Change

    I think it will be useful if you attached a sample workbook ...

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Call Private Sub Worksheet_Change

    BrianAll‎,


    Try something like
        Run "sheet1.worksheet_change", Sheet1.Range("a1")
    Change a1 to suite if needed.
    Last edited by jindon; 02-06-2019 at 01:23 AM.

  11. #11
    Registered User
    Join Date
    06-19-2013
    Location
    Sheffield
    MS-Off Ver
    Excel 2013
    Posts
    86

    Re: Call Private Sub Worksheet_Change

    It works!
    Thanks jindon

+ 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. Call Private Function under Private Sub
    By thanhthinh1234 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-25-2018, 03:23 AM
  2. [SOLVED] combine two Private Sub Worksheet_Change
    By mazan2010 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-02-2016, 03:32 AM
  3. [SOLVED] How to Combine two Private Sub Worksheet_Change ?
    By stoicy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-17-2016, 04:34 PM
  4. How do I include two Private Sub Worksheet_Change’s
    By Jessy01 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-16-2013, 12:24 PM
  5. Combining two Private Sub Worksheet_Change
    By bdf0827 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-14-2011, 08:58 AM
  6. Private Sub Worksheet_Change
    By VicM in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-15-2008, 01:28 AM
  7. Private Sub Worksheet_Change:do i need to turn them into one?
    By alex1982 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-03-2007, 06:43 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