Automate Microsoft Excel WorkBook

Good Afternoon,

I have a workbook in excel 2013 that I use to make a log of my duties each day.

At the moment to automate the form a bit, I am using some strings for some of the cells that I was able to figure out from online forums.

I would like the form to be a bit more automated and read online that macros can achieve this.

I have the workbook attached (OPLOG.xlsm) and would be grateful if someone can create a macro for me which will achieve what I want it to do.

Please note:

1.      The worksheet cannot be changed in any way and must remain the same with the layout, so adding more columns or moving things around is NOT an option.
2.      I would like all strings I have already in certain cells to be controlled by the macro (I will list what I want below). That way there will be no accidental deletion if I accidentally delete the code from the cell. So once the macro works there would be no need to have the strings in the cells anymore.
3.      I am not interested at this time of any suggestions or other applications that will accomplish this etc, I would just like to make this form work in the way I have listed below using a macro behind the scenes for it.
4.      All highlights, illustrations and red writing in the screenshots below are just there to give a clearer picture of what I want the macro to accomplish.

My requests for the Macro:

1.      Upon launch of workbook I would like the processing date to automatically set to today’s date, this cell is currently using the string =CONCATENATE("Processing date: ",TEXT(TODAY(),"mm/dd/yyyy")) but I would like to have the Macro do this instead.
procdate
2.      I would like for when I double click in cell A10 that the macro will automatically populate:
a.       B10, B12 and B13 with an X. Currently I am using this string =IFERROR(IF(SEARCH("*x*",B10,1),"x"),"") in cell B12 and B13 but would like the macro to do this instead.
b.      Display the operator name (SDiallo) in cell C16. Currently I am using this string =IFERROR(IF(SEARCH("*x*",B10,1),"SDiallo"),"") in cell C16 but would like the macro to do this instead.
c.      Set cell C11 to read Start Time: CurrentSystemTime (hh:mm AM/PM) Example: 10:00 AM. I currently have to put the time in manually, but would like the macro to do this instead.
d.      Set cell C14 to read End Time: 8 minutes later (hh:mm AM/PM) Example: 10:08 AM. I currently have to put the time in manually, but would like the macro to do this instead.

3.      Same as above but for cell A20 and the specific cells below for that section. See screenshot below on the amount of minutes for the time difference.

4.      Same as above but for cell A30 and the specific cells below for that section. See screenshot below on the amount of minutes for the time difference.
doubleclik
5.      I would like for when the workbook is first opened to clear the below cells:
a.      B10, B12, B13, B16, B20, B22, B23, B26, B30, B32, B33, B36 (so the X and the operators name in these boxes will be removed if they exist in these boxes when the workbook is first opened).
b.      B11, B14, B21, B24, B31, B34 (for these cells I want the times cleared and just a default value of Start Time: and End Time: to be displayed when the workbook is first opened).
clearing
Kindly advise.

Regards,
K
OPLOG.xlsm
LVL 1
KevinInformation TechnologyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
I believe this does what you want.
29126506.xlsm
Martin LissOlder than dirtCommented:
I overlooked the requirement for the 2nd and 3rd operator signature.
29126506a.xlsm

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KevinInformation TechnologyAuthor Commented:
Good Evening Martin,

This is brilliant, thank you.

I had to tweak it a little bit as I think you weren't to clear on my request. So now the code looks like this:

Private Sub Workbook_Open()
Dim cel As Range
With ThisWorkbook.Sheets("OPLOG")
    .Range("B10:B36").ClearContents
    For Each cel In .Range("C11:C36")
        If cel Like "*:*" Then
            cel = Split(cel, ":")(0) & ":"
        End If
    Next
    .Range("E4") = "Processing date: " & Format(Now, "mm/dd/yyyy")
End With
End Sub

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim strDate As String
If Sh.Name = "OPLOG" Then
    If Target.Address = "$A$10" Then
        Sh.Range("B10") = "X"
        Sh.Range("B12") = "X"
        Sh.Range("B13") = "X"
        strDate = Format(Time, "h:mm AM/PM")
        
        Sh.Range("C11") = "Start Time: " & strDate
        Sh.Range("C14") = "End Time: " & Format(DateAdd("n", 8, strDate), "h:mm AM/PM")
        Sh.Range("C16") = "SDiallo"
                 
    ElseIf Target.Address = "$A$20" Then
        Sh.Range("B20") = "X"
        Sh.Range("B22") = "X"
        Sh.Range("B23") = "X"
        strDate = Format(Time, "h:mm AM/PM")
        
        Sh.Range("C21") = "Start Time: " & strDate
        Sh.Range("C24") = "End Time: " & Format(DateAdd("n", 3, strDate), "h:mm AM/PM")
        Sh.Range("C26") = "SDiallo"
    
    ElseIf Target.Address = "$A$30" Then
        Sh.Range("B30") = "X"
        Sh.Range("B32") = "X"
        Sh.Range("B33") = "X"
        strDate = Format(Time, "h:mm AM/PM")
        
        Sh.Range("C31") = "Start Time: " & strDate
        Sh.Range("C34") = "End Time: " & Format(DateAdd("n", 2, strDate), "h:mm AM/PM")
        Sh.Range("C36") = "SDiallo"
    
    End If
End If
End Sub

Open in new window


There is just one more thing that needs fixing but I can't figure it out.

I made a typo on request point 5a, B16, B26 and B36 should really be C16, C26 and C36, to clear the operators name as well upon opening the workbook.

I have tried a few things like below (see line 4), but can't figure out what to put. Can you have a look please and tell me what I need to change to have the operators name cleared upon opening the workbook?

Private Sub Workbook_Open()
Dim cel As Range
With ThisWorkbook.Sheets("OPLOG")
    .Range("B10:B36" & "C16" & "C26" & "C36").ClearContents	
    For Each cel In .Range("C11:C36")
        If cel Like "*:*" Then
            cel = Split(cel, ":")(0) & ":"
        End If
    Next
    .Range("E4") = "Processing date: " & Format(Now, "mm/dd/yyyy")
End With
End Sub

Open in new window


Kindly advise.

Regards,
K
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Martin LissOlder than dirtCommented:
It's not clear to me if you want to clear both  "B10:B36" and  "C16", "C26" and "C36" or just "C16", "C26" and "C36". If it's the former then change .Range("B10:B36" & "C16" & "C26" & "C36").ClearContents to .Range("B10:B36,C16,C26,C36").ClearContents. If it's the latter then change it to .Range("C16,C26,C36").ClearContents.
KevinInformation TechnologyAuthor Commented:
Good Evening Martin,

Yes I wanted to clear all fields (column B and C) upon opening the workbook.

Code now looks like this:

Private Sub Workbook_Open()
Dim cel As Range
With ThisWorkbook.Sheets("OPLOG")
    .Range("B10:B36,C16,C26,C36").ClearContents
    For Each cel In .Range("C11:C36")
        If cel Like "*:*" Then
            cel = Split(cel, ":")(0) & ":"
        End If
    Next
    .Range("E4") = "Processing date: " & Format(Now, "mm/dd/yyyy")
End With
End Sub

Open in new window


Thank you very much for this. I really appreciate it.

Kind Regards,
K
KevinInformation TechnologyAuthor Commented:
Thanks again.
Martin LissOlder than dirtCommented:
You’re welcome and I’m glad I was able to help.

If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
              Experts Exchange Top Expert VBA (current)
KevinInformation TechnologyAuthor Commented:
Neat.

Thanks for sharing.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.