• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro to run a specific days and date and time embedded in another macro

RAM72

Member
Hi All

Macro to run at specific date,days and time and modulable.

That is macro will check these three criterias above to run another sub otherwise say " Not authorised any more "
sample
So date may be 01/02/2016 to 25/02/2016
Days:Monday to Thursday
or Monday , Thursday , Saturday
Time :10:10 am to 17:00 pm
It should be embedded in another macro as below and modulable to other macros if possible in order for the other sub to work

Thanks if any can help

Code:
Sub Button1_Click()



    Dim x      As Long
    Dim arr()  As Variant
    Dim temp    As Variant
    Dim ws1    As Worksheet
    Dim ws2    As Worksheet
    Dim dic    As Object
   
    Const delim As String = "|"
   
    Set ws1 = Sheets("Input Datasheet")
    Set ws2 = Sheets("Product DataBase ")
    Set dic = CreateObject("Scripting.Dictionary")


    Application.ScreenUpdating = False
   
    With ws2
        For x = 1 To .Cells(.Rows.Count, 3).End(xlUp).Row
            dic(Val(.Cells(x, 3).Value)) = .Cells(x, 1).Value & delim & .Cells(x, 2).Value
        Next x
    End With
   
    With ws1
        x = .Cells(.Rows.Count, 3).End(xlUp).Row
        arr = .Cells(2, 1).Resize(x - 1, 4).Value
       
        For x = LBound(arr, 1) To UBound(arr, 1)
            If dic.exists(.Cells(x + 1, 3).Value) Then
                temp = Split(dic(.Cells(x + 1, 3).Value), delim)
                arr(x, 1) = temp(0)
                arr(x, 2) = temp(1)
                Erase temp
            Else
                arr(x, 1) = Empty
                arr(x, 2) = Empty
            End If
        Next x
       
        .Cells(2, 1).Resize(UBound(arr, 1), UBound(arr, 2)).Value2 = arr
    End With
   
    Application.ScreenUpdating = True
   
    Set dic = Nothing
    Set ws1 = Nothing
    Set ws2 = Nothing
    Erase arr
   
End Sub
 
Something like attached?

I'd suggest setting the sheet where parameters (valid range) are stored to xlSheetVeryHidden to avoid users altering the parameter.

All parameters are set as named range in Sheet2.
 

Attachments

  • Macro Book(1).xlsm
    24.5 KB · Views: 6
Something like attached?

I'd suggest setting the sheet where parameters (valid range) are stored to xlSheetVeryHidden to avoid users altering the parameter.

All parameters are set as named range in Sheet2.
Thanks I have a look and advise you :)
 
Back
Top