Code not rerunning like intended

Jake975

Board Regular
Joined
Feb 9, 2020
Messages
114
Office Version
  1. 2016
Platform
  1. Windows
This code determines what version of the code is run biased on the step
VBA Code:
Private Sub UserForm_Activate()

iStepCurrent = NightAuditP.iStepCurrent
'iStepCurrent = 6
Select Case iStepCurrent
Case 6 Or 7
    Call CK1
Case 15 Or 16
    Call Me.CK2
End Select

If Me.ListBox1.ListCount > 0 Then
 Me.Cleared.Enabled = False
   End If

End Sub
VBA Code:
Sub CK2()
    Dim DirectoryListArray As Variant, sPath As String
    Dim rg As Range, i As Long, j As Long
    
sPath = "G:\Shared drives\437 - HIE Malvern - All Users\Front desk\Night Audit\Audit Reports\Disembodied\" & Format(Date - 1, "MM-DD-YYYY") + "\"
    DirectoryListArray = GetFiles(sPath)
    
    Set rg = Worksheets("Data List").Cells(1, 1).CurrentRegion
    Set ufDic = CreateObject("Scripting.Dictionary")
    For j = 2 To rg.Rows.Count
       If Not rg.Cells(j, 7) = vbNullString Then
           If UBound(Filter(DirectoryListArray, rg.Cells(j, 7), 1, 1)) < 0 Then
               ufDic.Item(rg.Cells(j, 3).Value) = rg.Cells(j, 8).Value
           End If
       End If
    Next j
    
  Me.ListBox1.List = ufDic.Keys          'Adapt to your needs
Me.Show
End Sub
My issue is when the form starts the first time it loads correctly but the second time around when the code is run it starts correct but if i relaunch the form it doesn't
what do i need to do to get it to load right
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hello Jake975,
let me try to help you.
Change "Select Case" "OR" to "TO"

VBA Code:
Dim iStepCurrent As integer

Private Sub UserForm_Activate()

    iStepCurrent = NightAuditP.iStepCurrent
    'iStepCurrent = 6
    Select Case iStepCurrent
    Case 6 To 7
        Call CK1
    Case 15 To 16
        Call Me.CK2
    End Select

End Sub

And hide userform before activate it again
VBA Code:
    Me.Hide
    Me.Show
End Sub
 
Upvote 0
Hello Excel MAX,
Thank you for the suggestion. When I posted this I was having an issue of where the form would activate correct but when I would unload then reload it aka refresh it would show blank. I say all this because I originally had both macros in one form thats why I used the case select but when I was having issues with the loading of the information I split it into two different forms. When I did that i copied the code from the working form to the new one because they were basically the same but I never updated the refresh code for the new form so what was happening it was unloading the current form then loading the old form.
Long story short thank you for making me take a closer look and I will try the "to" in the case select to see if I can then combine the two forms into one again.
Again Thanks
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,309
Members
449,080
Latest member
jmsotelo

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