+ Reply to Thread
Results 1 to 5 of 5

Change Worksheet_Change Event to normal macro

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-08-2018
    Location
    Denmark
    MS-Off Ver
    2016 for Windows
    Posts
    413

    Change Worksheet_Change Event to normal macro

    I need to change this Change_Event to a sub I can call from other sub

    Is it possible

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cRow As Long
    Dim eRng As Range
    
    
    cRow = Target.Row
    Set eRng = Range("F8:CX2000")
    
    If Not Intersect(Target, eRng) Is Nothing Then
        With Application
            .EnableEvents = False
    
            With Sheet70 '<<--- Adjust the sheet here
                .Unprotect "Password"
    
                .Cells(cRow, 102) = IIf(Application.CountA(Me.Cells(cRow, 6).Resize(1, 101)) > 0, Cells(cRow, 5), "")
         .Protect "Password"
        End With
    
         .EnableEvents = True
         End With
    End If
    End Sub

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: Change Worksheet_Change Event to normal macro

    The Worksheet_Change event procedure is triggered by changes to the worksheet. If your other sub makes changes to the worksheet, it is in effect calling the Worksheet_Change procedure.


    If you want to make it a standalone procedure, You could use just this part of the code.

            With Sheet70 '<<--- Adjust the sheet here
                .Unprotect "Password"
    
                .Cells(cRow, 102) = IIf(Application.CountA(Sheets("Sheet1").Cells(cRow, 6).Resize(1, 101)) > 0, Sheets("Sheet1").Cells(cRow, 5), "")
         .Protect "Password"
    Change the Sheet1 to the name of the sheet that was changed. And define the cRow as the row number that your code changed.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    03-08-2018
    Location
    Denmark
    MS-Off Ver
    2016 for Windows
    Posts
    413

    Re: Change Worksheet_Change Event to normal macro

    Thanks AlphaFrog
    I get this Error.
    I am not shure how I define the cROw


    1.JPG

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: Change Worksheet_Change Event to normal macro

    Target is not defined. In the Worksheet_Change procedure, Target is the cell(s) that were changed. In your procedure, you have to specify what cells were changed. You have to define Target as a range of cell(s).

  5. #5
    Forum Contributor
    Join Date
    03-08-2018
    Location
    Denmark
    MS-Off Ver
    2016 for Windows
    Posts
    413

    Re: Change Worksheet_Change Event to normal macro

    Thanks for your help,

    I am not shure on how to define that. It can be any Cell in Range("F8:CW1000")

    Sub PivotDate()
    
    Dim cRow As Long
    Dim eRng As Range
    Dim Target As Range
    Dim Data As Object
    cRow = ThisWorkbook.Sheets("DATA").Range("F8:CX1000")
    Set eRng = ThisWorkbook.Sheets("DATA").Range("F8:CX1000")
    Set Target.Row = ThisWorkbook.Sheets("DATA").Range("F8:CX1000")
    cRow = Target.Row
    
        With Application
            .EnableEvents = False
            With Sheet70 '(DATA)
                .Unprotect "*DM2285dm2018*"
    
                .Cells(cRow, 102) = IIf(Application.CountA(Sheets("DATA").Cells(cRow, 6).Resize(1, 101)) > 0, Sheets("DATA").Cells(cRow, 5), "")
         .Protect "*DM2285dm2018*"
        End With
    
         .EnableEvents = True
         End With
    End Sub

+ 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. Macro to change hexadecimal values to normal
    By toravietl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-11-2014, 11:36 AM
  2. Worksheet_Change Event does not execute upon change of cell
    By KarlaM in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-11-2013, 07:04 PM
  3. Run Macro On Data Validation List Without Worksheet_Change Event?
    By runofthemill in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-27-2013, 04:12 PM
  4. Worksheet_Change Event - How to initiate a Macro?
    By Jimbo42 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-25-2013, 09:01 PM
  5. change the (Worksheet_Change) event for a module (Sub).
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-07-2012, 01:37 PM
  6. Run an Event Worksheet_Change Macro
    By gazzz_tha1 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-24-2010, 01:29 AM
  7. Run time error 13 when deleting more than one cell with Worksheet_Change event macro
    By som3on3_10 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-22-2010, 12:19 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