Need A Macro

syedjaveed

New Member
Joined
Feb 28, 2013
Messages
37
Hi Team,

Please help me with a coding.

I Generally have 7 Queues (Log in, Meeting, Break, East Queue, West Queue, Others,Log out) in a range B5 as a drop down list

And
Just below that i have a start time and end time cells in B6 and B7.

I want such a macro where if i select any dropdown from B5 the start time shud appear and when i change the dropdown then a specific range us given where the Start time and End time should get capture and simultaneously the again the new start time should come when i change the Drop down.

please see the below format. And Suggest if it is possible to do so.

Excel Workbook
ABCDEFG
1
2NameNBKPerson #
3
4
5CodeBreak
6Start Time
7End Time
8
9
10NameNBKPerson #CodeStart TimeEnd TimeComments
11
12
13
14
15
16
17
18
19
20
21
22
Sheet1


Thanks n Regards
Javeed
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim LastRow As Long
    If Target.Address <> "$B$5" Then Exit Sub
    Application.EnableEvents = False
    LastRow = Range("A" & Rows.Count).End(xlUp).Row
    Range("A" & LastRow + 1).Value = Range("A3").Value
    Range("B" & LastRow + 1).Value = Range("B3").Value
    Range("C" & LastRow + 1).Value = Range("C3").Value
    Range("D" & LastRow + 1).Value = Target.Value
    With Range("E" & LastRow + 1)
        .NumberFormat = "dd/mm/yyyy hh:mm:ss"
        .Value = Date + Time
    End With
    Range("B6").Value = Range("E" & LastRow + 1).Value
    If LastRow > 10 Then
        With Range("F" & LastRow)
            .NumberFormat = "dd/mm/yyyy hh:mm:ss"
            .Value = Date + Time
        End With
    End If
    Application.EnableEvents = True
End Sub

I don't think you need to record End Time in B7.
 
Upvote 0
Try:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim LastRow As Long
    If Target.Address <> "$B$5" Then Exit Sub
    Application.EnableEvents = False
    LastRow = Range("A" & Rows.Count).End(xlUp).Row
    Range("A" & LastRow + 1).Value = Range("A3").Value
    Range("B" & LastRow + 1).Value = Range("B3").Value
    Range("C" & LastRow + 1).Value = Range("C3").Value
    Range("D" & LastRow + 1).Value = Target.Value
    With Range("E" & LastRow + 1)
        .NumberFormat = "dd/mm/yyyy hh:mm:ss"
        .Value = Date + Time
    End With
    Range("B6").Value = Range("E" & LastRow + 1).Value
    If LastRow > 10 Then
        With Range("F" & LastRow)
            .NumberFormat = "dd/mm/yyyy hh:mm:ss"
            .Value = Date + Time
        End With
    End If
    Application.EnableEvents = True
End Sub

I don't think you need to record End Time in B7.

Hi Sir,

I copied the code into the vb window.

however when iam changing the dropdown(B5) its not working. I mean the start date is not coming.

Please assist how to go about it.

Thank You.
 
Upvote 0
The procedure needs to go in the module for the worksheet, not a general module.


The Procedure i followed. Please suggest if iam wrong.

From Developer Tab>Visual Basic>(VB window opened)>Insert>Module>In Module1 i pasted the code and saved the workbook as macro enabled workbook
 
Upvote 0
Hi syedjaveed,

The Procedure i followed. Please suggest if iam wrong.

From Developer Tab>Visual Basic>(VB window opened)>Insert>Module>In Module1 i pasted the code and saved the workbook as macro enabled workbook

You need to RIGHT click on the WorkSheet TAB and select View Code, then paste the procedure in there.

I hope this helps!
 
Upvote 0
No, in Excel right click the sheet tab and choose View Code. Then paste the code in the window on the right. The code must go in the module for Sheet1, not in a module that you insert.
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,554
Members
448,970
Latest member
kennimack

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