+ Reply to Thread
Results 1 to 6 of 6

Run Code When E2 or E3 Change

Hybrid View

  1. #1
    Banned User!
    Join Date
    06-18-2021
    Location
    Peru
    MS-Off Ver
    2010, Microsoft 365
    Posts
    431

    Run Code When E2 or E3 Change

    Hi,

    Could the code below be modified so when cells E2 or E3 change it runs?

    Thank you

    Sub FIL()
    Dim a
    On Error Resume Next
    With Sheet2
        If .ListObjects(1).ListRows.Count Then .ListObjects(1).DataBodyRange.Delete
        a = .Evaluate("FILTER(Table1,TEXT(Table1[Date],""[$-en]mmmmyyyy"")=E3&E2)")
        .[B7].Resize(UBound(a), 6) = a
    End With
    End Sub

  2. #2
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: Run Code When E2 or E3 Change

    Try this in your Sheet's Module.
    Option Explicit
    Dim pWB As Workbook
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Set pWB = Workbooks(ThisWorkbook.Name)
    Dim wSheet As Worksheet
    Dim rRange As Range
    Set wSheet = pWB.Worksheets("Sheet2")
    Set rRange = wSheet.Range("$E$2:$E$3")
    If Not Intersect(Target, rRange) Is Nothing Then
    
    'Start your Code Here
    
    Dim a
    On Error Resume Next
    With Sheet2
        If .ListObjects(1).ListRows.Count Then .ListObjects(1).DataBodyRange.Delete
        a = .Evaluate("FILTER(Table1,TEXT(Table1[Date],""[$-en]mmmmyyyy"")=E3&E2)")
        .[B7].Resize(UBound(a), 6) = a
    End With
    
    'End your Code Here
    
    End If
    End Sub

  3. #3
    Banned User!
    Join Date
    06-18-2021
    Location
    Peru
    MS-Off Ver
    2010, Microsoft 365
    Posts
    431

    Re: Run Code When E2 or E3 Change

    Thanks but it goes to debug at Set wSheet line

  4. #4
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: Run Code When E2 or E3 Change

    Quote Originally Posted by BillySpivy View Post
    Thanks but it goes to debug at Set wSheet line
    Change "Sheet2" in that line of code to the name of your sheet you are calling the code from.

  5. #5
    Banned User!
    Join Date
    06-18-2021
    Location
    Peru
    MS-Off Ver
    2010, Microsoft 365
    Posts
    431

    Re: Run Code When E2 or E3 Change

    Ah that works great you are a super genius thanks!

  6. #6
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: Run Code When E2 or E3 Change

    Glad it works!

+ 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. Change font color of multiple objects at once with shorter code?
    By frankytheman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-20-2020, 01:28 AM
  2. change date format in VBA code it means change output when printing cheque
    By keshavtale in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-23-2019, 06:06 AM
  3. Need to change sample code columns for subtotals and the column for a change event
    By JoeVanGeaux in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-09-2017, 09:02 PM
  4. Replies: 3
    Last Post: 07-01-2015, 09:53 PM
  5. [SOLVED] Trying to change verbose looping code into more efficient (and shorter) code please
    By dawatcher in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-03-2013, 07:43 AM
  6. Replies: 4
    Last Post: 07-09-2012, 04:15 PM
  7. Replies: 15
    Last Post: 04-17-2012, 08:19 AM

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