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.
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.
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).
Kindly advise.
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 RangeWith 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 WithEnd SubPrivate Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)Dim strDate As StringIf 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 IfEnd IfEnd Sub
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 RangeWith 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 WithEnd Sub
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 RangeWith 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 WithEnd Sub