Worksheet Change Dropdown Works Once

neomapper1

New Member
Joined
Jul 1, 2021
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
I have a script that runs an action change based on AA3 when a change occurs but it only works once. How would I keep running if I change the dropdown?





VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim Path As String
Dim Filename As String

Dim Office As String
Dim HouseNo As String
Dim Street As String
Dim Unit As String
Dim URL As String
Dim CloudLancaster As String
Dim strInput As String
Dim Result As String
Dim InStr As String

Office = Range("AA3").Value
HouseNo = Range("A5").Value
Street = Range("G5").Value
Unit = Range("S5").Value

' Cloud Varibles
CloudLancaster = "https://link.egnyte.com/app/index.do#/"


If Not Intersect(Target, Range("AA3")) Is Nothing Then
    If InStr(1, Target.Value, "Lancaster") > 0 Then
        If Target <> olval Then
            Application.EnableEvents = False
            Filename = Format(Range("G4"), "[COLOR=#ff0000]dd-mm-yyyy[/COLOR]")
            olval = Filename
            Path = "Z:\Shared\Enterprise File Shares\NEO_Assignments\2021 Work Orders\1) Lancaster Office\0_Service_Request\"
                If IsEmpty(Range("S5").Value) = True Then
                    URL = Path & Office & " - " & HouseNo & " " & Filename
                    MkDir URL
                    ActiveWorkbook.SaveAs Filename:=URL & "\" & Office & " - " & HouseNo & " " & Filename & " " & ".xls"
                    strReplace = Office & " - " & HouseNo & " " & Filename
                    Result = Replace(strReplace, " ", "%20")
                    InputBox "Copy the link to Star", "Egnyte Link", CloudLancaster & Result
                Else
                    URL = Path & Office & " - " & HouseNo & " " & Filename & " Unit# " & Unit
                    MkDir URL
                    ActiveWorkbook.SaveAs Filename:=URL & "\" & Office & " - " & HouseNo & " " & Filename & " Unit# " & Unit & ".xls"
                    Application.EnableEvents = True
                    strReplace = Office & " - " & HouseNo & " " & Filename & " Unit# " & Unit
                    Result = Replace(strReplace, " ", "%20")
                    InputBox "Copy the link to Star", "Egnyte Link", CloudLancaster & Result
                End If
        End If
    End If
End If
End Sub
 

Attachments

  • 1626375830503.png
    1626375830503.png
    89.7 KB · Views: 7

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Welcome to the Board!

I think it is because of the location of this line:
VBA Code:
Application.EnableEvents = True
If your code meets the first condition of your inner-most IF...THEN block, that line of code will not run, so events won't be re-enabled.

Try moving it in to the same IF... THEN block as the one that turns it off, i.e.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim Path As String
Dim Filename As String

Dim Office As String
Dim HouseNo As String
Dim Street As String
Dim Unit As String
Dim URL As String
Dim CloudLancaster As String
Dim strInput As String
Dim Result As String
Dim InStr As String

Office = Range("AA3").Value
HouseNo = Range("A5").Value
Street = Range("G5").Value
Unit = Range("S5").Value

' Cloud Varibles
CloudLancaster = "https://link.egnyte.com/app/index.do#/"


If Not Intersect(Target, Range("AA3")) Is Nothing Then
    If InStr(1, Target.Value, "Lancaster") > 0 Then
        If Target <> olval Then
            Application.EnableEvents = False
            Filename = Format(Range("G4"), "[COLOR=#ff0000]dd-mm-yyyy[/COLOR]")
            olval = Filename
            Path = "Z:\Shared\Enterprise File Shares\NEO_Assignments\2021 Work Orders\1) Lancaster Office\0_Service_Request\"
                If IsEmpty(Range("S5").Value) = True Then
                    URL = Path & Office & " - " & HouseNo & " " & Filename
                    MkDir URL
                    ActiveWorkbook.SaveAs Filename:=URL & "\" & Office & " - " & HouseNo & " " & Filename & " " & ".xls"
                    strReplace = Office & " - " & HouseNo & " " & Filename
                    Result = Replace(strReplace, " ", "%20")
                    InputBox "Copy the link to Star", "Egnyte Link", CloudLancaster & Result
                Else
                    URL = Path & Office & " - " & HouseNo & " " & Filename & " Unit# " & Unit
                    MkDir URL
                    ActiveWorkbook.SaveAs Filename:=URL & "\" & Office & " - " & HouseNo & " " & Filename & " Unit# " & Unit & ".xls"
                    strReplace = Office & " - " & HouseNo & " " & Filename & " Unit# " & Unit
                    Result = Replace(strReplace, " ", "%20")
                    InputBox "Copy the link to Star", "Egnyte Link", CloudLancaster & Result
                End If
            Application.EnableEvents = True
        End If
    End If
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top