+ Reply to Thread
Results 1 to 9 of 9

code to record an amount into a table

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-24-2012
    Location
    San Diego, USA
    MS-Off Ver
    Excel 2019
    Posts
    871

    code to record an amount into a table

    I would like a very simple payroll, I only have 3 people working, so let say I would like to enter the name of employee and enter the amount of money pay for that week (an automatic date) enter into a table , but instead of open a sheet if I can just use a form and use a button to click on it. Please give me a sample or idea on how I can do this. Thank you.
    Last edited by chubbychub; 03-11-2018 at 01:21 AM.

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: code to record an amount into a table

    This tutorial should help get you started.

    Build a UserForm for Excel
    HTH
    Regards, Jeff

  3. #3
    Forum Contributor
    Join Date
    10-24-2012
    Location
    San Diego, USA
    MS-Off Ver
    Excel 2019
    Posts
    871

    Re: code to record an amount into a table

    Ok, I have modified the userform to kind of what I want, I want to change each person to have a separate sheet, for example, carlos to have its own sheet, jesus on his own sheet, Charlie on his own sheet. How can I do that? or if someone can help me do that please, please look at attachmemnt.
    Attached Files Attached Files
    Last edited by chubbychub; 03-16-2018 at 12:07 AM. Reason: forgot attachment

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: code to record an amount into a table

    This works with a sheet for each cboDepartment.Value (it'll install a new sheet)

    Private Sub cmdOK_Click()
        Dim RowCount As Long
        Dim ctl As Control
        Dim ws As Worksheet, N As String, Z
        N = Me.cboDepartment.Value: Z = Split(N): N = Z(0)
        For Each ws In Worksheets
        If ws.Name = N Then GoTo Setws
        Next
    Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = N
        Sheets("Sheet1").Rows(1).Copy Sheets(N).Range("A1")
        
    Setws:    Set ws = Sheets(N)
    ' Write data to worksheet
        RowCount = ws.Range("A1").CurrentRegion.Rows.Count
        With ws.Range("A1")
            .Offset(RowCount, 0).Value = Me.cboDepartment.Value
            .Offset(RowCount, 1).Value = Me.txtAmount.Value
            .Offset(RowCount, 2).Value = Format(Now, "dd/mm/yyyy")
    
        End With
    ' Clear the form
        For Each ctl In Me.Controls
            If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
                ctl.Value = ""
            ElseIf TypeName(ctl) = "CheckBox" Then
                ctl.Value = False
            End If
        Next ctl
    End Sub
    Last edited by xladept; 03-17-2018 at 12:35 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  5. #5
    Forum Contributor
    Join Date
    10-24-2012
    Location
    San Diego, USA
    MS-Off Ver
    Excel 2019
    Posts
    871

    Re: code to record an amount into a table

    That works! thank you ! Xladept and jefreybrown! reputation added.
    I have changed as far as I can with the limited knowledge I have, I have created a button in the userform called "Savings". Can someone add the code to add a savings amount entered into the next column? For example, when I click on savings, it will add the amount in column E and the date in column F (of course corresponding to each person), thanks in advance.
    please look at attachment.
    Attached Files Attached Files

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: code to record an amount into a table

    You're welcome and thanks for the rep!

    Maybe:

    Private Sub cmdOK_Click()
        Dim RowCount As Long
        Dim ctl As Control
        Dim ws As Worksheet, N As String, Z, r As Long, S As Single
        N = Me.cboDepartment.Value: Z = Split(N): N = Z(0)
        For Each ws In Worksheets
        If ws.Name = N Then GoTo Setws
        Next
    Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = N
        Sheets("Lista").Rows(1).Copy Sheets(N).Range("A1")
        
    Setws:    Set ws = Sheets(N)
    ' Write data to worksheet
        RowCount = ws.Range("A1").CurrentRegion.Rows.Count
        With ws.Range("A1")
            .Offset(RowCount, 0).Value = Me.cboDepartment.Value
            .Offset(RowCount, 1).Value = Me.txtAmount.Value
            .Offset(RowCount, 2).Value = Format(Now, "dd/mm/yyyy")
            For r = 2 To RowCount + 1: S = S + CSng(ws.Range("B" & r)): Next r
            .Offset(RowCount, 4).Value = S: S = 0
            .Offset(RowCount, 5).Value = .Offset(RowCount, 2).Value
    
        End With
    ' Clear the form
        For Each ctl In Me.Controls
            If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
                ctl.Value = ""
            ElseIf TypeName(ctl) = "CheckBox" Then
                ctl.Value = False
            End If
        Next ctl
    End Sub

  7. #7
    Forum Contributor
    Join Date
    10-24-2012
    Location
    San Diego, USA
    MS-Off Ver
    Excel 2019
    Posts
    871

    Re: code to record an amount into a table

    Thank you xladept, I have work on it more, and almost done, currently the code adds the name over and over again on columnA, is there a way to change the code to check, if name already on A2 cell, then no need to write the name, Please look at attchament.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    10-24-2012
    Location
    San Diego, USA
    MS-Off Ver
    Excel 2019
    Posts
    871

    Re: code to record an amount into a table

    I think I should close this trhead as my initial problem has been solved and start a new thread. Thank you though xladept.

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: code to record an amount into a table

    You're welcome and thanks for the rep!

+ 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. [SOLVED] Please tell me simple search vba code ? my vba vlookup code not working..
    By aliakbaram85 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-27-2018, 01:54 AM
  2. help needed making a simple payroll calculator
    By aphatmc in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-19-2017, 02:55 PM
  3. [SOLVED] Payroll Start and End Dates, need Payroll Period fix
    By colarguns in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-12-2014, 08:03 PM
  4. Need a simple VBA code
    By arcwayx in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-04-2012, 02:47 AM
  5. Sumproduct formula:Empl Code Payroll Code Amount
    By bluemeg in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-30-2009, 02:08 PM
  6. [SOLVED] Adding payroll stubs payroll calculator
    By Sable in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 08-05-2006, 12:40 PM
  7. help on this simple code... or not so simple?
    By bondcrash in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-18-2005, 07:25 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