Results 1 to 10 of 12

Thread: User Form entry in a second sheet - need help with VBA code

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Feb 2022
    Posts
    11
    Rep Power
    0
    Hi Alan,

    I will try to explain exactly what should happen with my file:
    1. when I click on "Form" button located in sheet1 a user form open and I enter all the data in this form (file attached in .jpg for you to see)
    2. I fill all the data in this form (there are some dropdown lists-except the Amount) for each field. The fields from user form are exactly the headers from column B to G located in Database sheet (Year, Month, Name, Project, Task, Amount)-see File1.jpg attached.
    3. When I click "SAVE" all the data are automatically added in Database sheet as a new line (less columns A and H that are auto filled) - please see File2.jpg attached.
    This is done by the following code and it is working just fine
    Code:
    Sub Submit_Data()
    
        Dim sh As Worksheet
        Dim sh1 As Worksheet
        Dim iRow As Long, colno As Integer, iCol As Long, rowno As Integer
        Dim iRow1 As Long, colno1 As Integer, iCol1 As Integer, reqdRow As Integer
        Set sh = ThisWorkbook.Sheets("Database")
        Set sh1 = ThisWorkbook.Sheets("Database1")
        iRow = [Counta(Database!A:A)] + 1
        iCol = Sheets("Database").Cells(1, Columns.Count).End(xlToLeft).Column - 1
        iRow1 = [Counta(Database1!A:A)] + 1
        iCol1 = Sheets("Database1").Cells(1, Columns.Count).End(xlToLeft).Column - 1
        
        Application.ScreenUpdating = False
        With sh
            .Cells(iRow, 1) = iRow - 1
            .Cells(iRow, 2) = UserFormTest.CmbYear.Value
            .Cells(iRow, 3) = UserFormTest.CmbMonth.Value
            .Cells(iRow, 4) = UserFormTest.CmbName.Value
            .Cells(iRow, 5) = UserFormTest.CmbProject.Value
            .Cells(iRow, 6) = UserFormTest.CmbTask.Value
            .Cells(iRow, 7) = UserFormTest.TxtAmount.Value
            .Cells(iRow, 8) = Application.UserName
        End With
    
    
     
        Call Reset
     
        Application.ScreenUpdating = True
     
        MsgBox "Date incarcate cu succes!"
    
    End Sub
    4. Now comes the part where I need help. I would like that when I click the "SAVE" button in my user form to add a new line in Database sheet as pct. 3 above (this is already working as described before) AND to add only the amount of 1000 to cell G20 from Database1 sheet (please see File3.jpg attached). That cell is the correspondent cell for the data that I filled in user form - Year 2022, Month April, Name bbb, Project Project5, Task Task2 as File1.jpg.

    Hope it make sense now.
    Thanks again!
    P.S. The link sent before for downloading the file was great but the issue with the amount from Database1 sheet didn't worked
    Attached Images Attached Images

Similar Threads

  1. Inserting Image In VBA User Form Caption
    By littleiitin in forum Download Center
    Replies: 3
    Last Post: 02-22-2021, 03:07 PM
  2. create invoice with user form
    By anil21 in forum Excel Help
    Replies: 7
    Last Post: 02-07-2018, 04:57 PM
  3. VBA Code for User Form
    By dkesar in forum Excel Help
    Replies: 1
    Last Post: 01-02-2015, 03:19 PM
  4. Replies: 5
    Last Post: 06-13-2014, 08:37 PM
  5. Replies: 7
    Last Post: 03-11-2014, 05:38 PM

Posting Permissions

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