We help IT Professionals succeed at work.

Automate Microsoft Excel WorkBook

93 Views
Last Modified: 2018-11-17
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
Comment
Watch Question

Martin LissSocial distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
I believe this does what you want.
29126506.xlsm
Social distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
KevinInformation Technology

Author

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
Martin LissSocial distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
KevinInformation Technology

Author

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 Technology

Author

Commented:
Thanks again.
Martin LissSocial distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
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 Technology

Author

Commented:
Neat.

Thanks for sharing.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.