+ Reply to Thread
Results 1 to 5 of 5

Click to count usage with value + date

  1. #1
    Registered User
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013
    Posts
    28

    Click to count usage with value + date

    1.jpg

    Hello, i wanto to use the userform i send in image to count the usage of four itens.

    if i click command 1 it will automaticly appear on cell a1 the number 1 and on cell a2 the date/time of the click. if command was clicked again the value would appear on the row below.


    The two command buttons bellow are used tho show or hide excel sheet. and the ohter one is a save and exit.

    Could anyone help me with the code?

    thanks

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Click to count usage with value + date

    Welcome to the forum! Good job posting an image. Often, a simple example attached file is a good way to help others help you. Attach by clicking the Go Advanced button in lower right of a reply box, and click the paperclip icon in toolbar or Manage Attachments link below reply box.

    Always test on a backup copy.

    In the userform's code:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013
    Posts
    28

    Re: Click to count usage with value + date

    Thanks.

    I´ve tested the code and changed to the other command buttons.

    Private Sub CommandButton1_Click()
    Dim r As Range, ws As Worksheet, calc As Integer

    Set ws = ActiveSheet 'Sheet1, Worksheets("Sheet1")

    calc = Application.Calculation
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    Application.EnableEvents = False

    With ws
    Set r = ws.Cells(ws.Rows.Count, "A").End(xlUp).Offset(1)
    'Row 1 is usually a columns title row so line is seldom needed.
    If r.Offset(-1).Value = "" Then Set r = r.Offset(-1) 'A1 could be ""
    r.Value = WorksheetFunction.Max(ws.Columns("A")) + 1
    With r.Offset(, 1)
    .Value = Now
    .NumberFormat = "mm/dd/yyyy h:mm:ss am/pm"
    End With
    End With

    Application.Calculation = calc
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    End Sub


    Private Sub CommandButton2_Click()

    Dim r As Range, ws As Worksheet, calc As Integer

    Set ws = ActiveSheet 'Sheet1, Worksheets("Sheet1")

    calc = Application.Calculation
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    Application.EnableEvents = False

    With ws
    Set r = ws.Cells(ws.Rows.Count, "C").End(xlUp).Offset(1)
    'Row 1 is usually a columns title row so line is seldom needed.
    If r.Offset(-1).Value = "" Then Set r = r.Offset(-1) 'C1 could be ""
    r.Value = WorksheetFunction.Max(ws.Columns("C")) + 1
    With r.Offset(, 1)
    .Value = Now
    .NumberFormat = "mm/dd/yyyy h:mm:ss am/pm"
    End With
    End With

    Application.Calculation = calc
    Application.ScreenUpdating = True
    Application.EnableEvents = True

    End Sub

    Private Sub CommandButton3_Click()

    Dim r As Range, ws As Worksheet, calc As Integer

    Set ws = ActiveSheet 'Sheet1, Worksheets("Sheet1")

    calc = Application.Calculation
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    Application.EnableEvents = False

    With ws
    Set r = ws.Cells(ws.Rows.Count, "E").End(xlUp).Offset(1)
    'Row 1 is usually a columns title row so line is seldom needed.
    If r.Offset(-1).Value = "" Then Set r = r.Offset(-1) 'E1 could be ""
    r.Value = WorksheetFunction.Max(ws.Columns("E")) + 1
    With r.Offset(, 1)
    .Value = Now
    .NumberFormat = "mm/dd/yyyy h:mm:ss am/pm"
    End With
    End With

    Application.Calculation = calc
    Application.ScreenUpdating = True
    Application.EnableEvents = True

    End Sub

    Private Sub CommandButton4_Click()
    Dim r As Range, ws As Worksheet, calc As Integer

    Set ws = ActiveSheet 'Sheet1, Worksheets("Sheet1")

    calc = Application.Calculation
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    Application.EnableEvents = False

    With ws
    Set r = ws.Cells(ws.Rows.Count, "G").End(xlUp).Offset(1)
    'Row 1 is usually a columns title row so line is seldom needed.
    If r.Offset(-1).Value = "" Then Set r = r.Offset(-1) 'G1 could be ""
    r.Value = WorksheetFunction.Max(ws.Columns("G")) + 1
    With r.Offset(, 1)
    .Value = Now
    .NumberFormat = "mm/dd/yyyy h:mm:ss am/pm"
    End With
    End With

    Application.Calculation = calc
    Application.ScreenUpdating = True
    Application.EnableEvents = True

    End Sub



    'Save (what, workbook) and exit
    Private Sub CommandButton5_Click()
    ThisWorkbook.Save
    Unload Me
    End Sub

    Private Sub CommandButton6_Click()

    Dim ws As Worksheet
    Set ws = ActiveSheet 'Sheet1, Worksheets("Sheet1")
    ws.Visible = xlSheetHidden

    End Sub

    Private Sub CommandButton7_Click()

    Dim ws As Worksheet
    Set ws = ActiveSheet 'Sheet1, Worksheets("Sheet1")
    ws.Visible = xlSheetVisible
    End Sub
    Am still having a problema to show or hide teh excel sheet and i have anoyher question. im reaaly a newbie in this.

    How can i make teh userform load on excel startup?

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Click to count usage with value + date

    In threaded forums, there is no need to quote a previous reply. Even if multiple posts, you can just say for example: in post #2, the code is...

    In VBE, open Project Explorer, View menu or Ctrl+R. Double click Thisworkbook object and paste:
    Please Login or Register  to view this content.
    If you are dealing with the same sheet, it is best to more explicit sheet references like the codename. e.g.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013
    Posts
    28

    Re: Click to count usage with value + date

    It worked with this code:

    Private Sub CommandButton6_Click()

    Application.Visible = True
    Me.Hide

    End Sub

    But know it hides all excell workbooks. Is there a way to hide only this one?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Workbook usage or Database usage assistance
    By Sunshine601 in forum Excel General
    Replies: 4
    Last Post: 12-12-2013, 08:36 AM
  2. Best way to display usage information across a large date range
    By Orionfi in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 04-19-2013, 03:10 PM
  3. Looking for a rolling max count of item usage
    By Befuddled in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 03-25-2013, 11:47 AM
  4. the click box was click but cannot save it and please help to add imported date
    By cherrychan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2013, 06:27 PM
  5. the click box was click but cannot save it and please help to add imported date
    By cherrychan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-06-2013, 06:51 PM
  6. Total Usage. Date Problem
    By treva26 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-31-2008, 03:02 AM
  7. Replies: 0
    Last Post: 03-10-2006, 11:30 PM
  8. Replies: 2
    Last Post: 10-12-2005, 11:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1