+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Registered User
    Join Date
    09-07-2009
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2003
    Posts
    19

    Question Saving userform to sheet

    Sorry Roy UK, thanks for correcting me.

    Hi all- I'm sorry I know I've posted it twice, I'm really under pressure and need to fix this fast!

    I'm creating what should be a fairly simple file. I have a userform that people fill in then they hit save and it writes to the worksheet "DATABASE". In the form you enter, amongst other info, the resource used and length of time. I then have a cell formula using VLOOKUP that calculates the cost based on the resource and time and another cell which adds this figure to the cost of the stock.

    However, because I copied these two formulas into their columns when I press save the vb code i have puts the data in the next empty line. So either I have to find a way to write the forumlas in the code or get the form to save to the sheet differently.

    Here's the code with the irrelevent stuff taken out.

    Code:
    Private Sub cmdSubmit_Click()
    
    Dim RowCount As Long
    Dim ctl As Control
    
    ' Check user input...
    
    ' Message to check first
    Dim confirm As VbMsgBoxResult
         
        confirm = MsgBox("Are you sure you want to submit?", _
        vbYesNo, "STOP: Submit Data")
        If confirm = 6 Then
    
    ' Write data to worksheet
    
    RowCount = Worksheets("Database").Range("A1").CurrentRegion.Rows.Count
    
    With Worksheets("Database").Range("A1")
    .Offset(RowCount, 0).Value = "P1088 (Bris)"
    .Offset(RowCount, 1).Value = "80192D"
    .Offset(RowCount, 2).Value = Me.txtWBS.Value
    .Offset(RowCount, 4).Value = Me.txtDoj.Value
    .Offset(RowCount, 5).Value = Me.txtAT.Value
    .Offset(RowCount, 7).Value = Me.txtSC.Value
    .Offset(RowCount, 8).Value = Me.txtJobdesc.Value
    .Offset(RowCount, 9).Value = Me.cmbAct.Value
    .Offset(RowCount, 10).Value = Me.txtWk.Value
    .Offset(RowCount, 11).Value = Me.cmbPN.Value
    .Offset(RowCount, 12).Value = Me.cmbFac.Value
    .Offset(RowCount, 13).Value = Me.txtBT.Value
    .Offset(RowCount, 14).Value = Me.txtPC.Value
    .Offset(RowCount, 15).Value = Me.txtStock.Value
    .Offset(RowCount, 16).Value = Me.txtMC.Value
    
    End With
    ' Clear form after submitting...
    As you can see numbers 3 and 6 are missing, these (columns C and F) are the ones with the formula already in. I tried switching it round so these were the first 2 columns and typing Range C1 at the start but that just errored and debugged highlighting that line of code.
    The formula in column F is =IF(ISERROR(VLOOKUP(S13,BACKGROUND!J:M,4,FALSE)=TRUE),"",VLOOKUP(S13,BACKGROUND!J:M,4,FALSE)) the forumla in C is =IF(I13="",0,SUM((H13*I13)+J13))
    Any ideas? I'm really stuck on this one and i need to complete the whole thing and enter almost 100 forms on it by tues evening! eek!
    many thanks,
    z
    Last edited by zebra; 09-18-2009 at 11:32 AM.

  2. #2
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: Saving userform to sheet

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  3. #3
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: Saving userform to sheet

    It doesn't matter how urgent this is to you, take the time to read the forum rules, then you will not get problems using the forum & would realise that you should not duplicate posts o any reason.

    It would probably help if you didn't use "shorthand" in Thread Titles as well!
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  4. #4
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: Saving userform to sheet

    Looks like your code will always write to A1 of the database

    Which column contains the formula?
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  5. #5
    Registered User
    Join Date
    09-07-2009
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Saving userform to sheet

    Columns C and F contain formula. I did try changing that to A and B and starting with cell C1 instead but it still just skipped to the next entirely blank row on the sheet.

  6. #6
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: Saving userform to sheet

    Test this
    Code:
    Private Sub cmdSubmit_Click()
    
    End Sub
    
    Dim RowCount   As Long
    
    
    ' Check user input...
    
    ' Message to check first
    Dim confirm    As VbMsgBoxResult
    
    confirm = MsgBox("Are you sure you want to submit?", _
                     vbYesNo, "STOP: Submit Data")
    If confirm = 6 Then
    
        ' Write data to worksheet
    
        RowCount = Worksheets("Database").Range("A1").CurrentRegion.Rows.Count
    
        With Worksheets("Database").Range("A1")
            .Offset(RowCount, 0).Value = "P1088 (Bris)"
            .Offset(RowCount, 1).Value = "80192D"
            .Offset(RowCount, 2).Value = Me.txtWBS.Value
            .Offset(RowCount, 3).FormulaR1C1 = "=IF(R[11]C[2]="""",0,SUM((R[11]C[1]*R[11]C[2])+R[11]C[3]))"
            .Offset(RowCount, 4).Value = Me.txtDoj.Value
            .Offset(RowCount, 5).Value = Me.txtAT.Value
            .Offset(RowCount, 3).FormulaR1C1 = _
            "=IF(ISERROR(VLOOKUP(R[3]C[13],BACKGROUND!C[4]:C[7],4,FALSE)=TRUE),"""",VLOOKUP(R[3]C[13],BACKGROUND!C[4]:C[7],4,FALSE))"
            .Offset(RowCount, 7).Value = Me.txtSC.Value
            .Offset(RowCount, 8).Value = Me.txtJobdesc.Value
            .Offset(RowCount, 9).Value = Me.cmbAct.Value
            .Offset(RowCount, 10).Value = Me.txtWk.Value
            .Offset(RowCount, 11).Value = Me.cmbPN.Value
            .Offset(RowCount, 12).Value = Me.cmbFac.Value
            .Offset(RowCount, 13).Value = Me.txtBT.Value
            .Offset(RowCount, 14).Value = Me.txtPC.Value
            .Offset(RowCount, 15).Value = Me.txtStock.Value
            .Offset(RowCount, 16).Value = Me.txtMC.Value
        End With
        ' Clear form after submitting...
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  7. #7
    Registered User
    Join Date
    09-07-2009
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Saving userform to sheet

    Hi,
    I subbed the formula in but it's not working. When I highlight the cell C3 what should be the total cost. I trace the precedents it shows cells E14, F14 and G14 which is wrong. Strangely when I trace precedents for cell G3 which should be the rate it highlights T6 with a blue line and E5 with a dashed black one.
    Hm I'm very confused. Could you explain to me what the R[11]C[2] means then maybe I can modify it to test? I guessed R means row and C column but then what do the numbers stand for?

    I don't know if it would be easier if I attach the spreadsheet up so you can see.

    Thank you very much for your help.

    Z

  8. #8
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: Saving userform to sheet

    Can you attach the a small file with some dummy data & the formulas in?
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  9. #9
    Registered User
    Join Date
    09-07-2009
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Saving userform to sheet

    Ok, here's a dummy template.
    Thanks for looking at it for me.

    Z
    Attached Files Attached Files

  10. #10
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: Saving userform to sheet

    Looking at the Database sheet I can see Column D has a formula, but not C or F
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  11. #11
    Registered User
    Join Date
    09-07-2009
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Saving userform to sheet

    Oh no, I've been rushing too much. It shouldn't be C or F but D and G. Basically the column 'Total Value' which should be the (Rate*Actual Hours)+Stock£ and the 'Rate' column which is the more complicated Lookup 'Item Name/resource code' then go to the BACKGROUND sheet and read from the code to the rate.

  12. #12
    Registered User
    Join Date
    09-07-2009
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Saving userform to sheet

    I guess the alternative is to abandon the userform and make the users enter into the spreadsheet and just have lots of drop-down menus? I literally just need to create the fastest possible way to enter the information but it is very important that the entry format is consistant so that we can sort the information. Currently it's just a big fat confusing mess! Ah but I do like userforms- they stop people from deleting and editing what they shouldn't.

  13. #13
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: Saving userform to sheet

    Can you attach a corrected workbook with the formulas in the correct column
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  14. #14
    Registered User
    Join Date
    09-07-2009
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Saving userform to sheet

    They are in the correct places on the dummy I just wrote the description wrong at the beginning.

  15. #15
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: Saving userform to sheet

    This should put the correct formula into the correct Column. You need to check that the other inputs are correct
    Code:
    With Worksheets("Database").Range("A1")
                .Offset(RowCount, 0).Value = "P1088 (Bris)"
                .Offset(RowCount, 1).Value = "80192D"
                .Offset(RowCount, 2).Value = Me.txtWBS.Value
                .Offset(RowCount, 4).FormulaR1C1 = "=IF(RC[3]="""",0,SUM((RC[2]*RC[3])+RC[4]))"
                .Offset(RowCount, 4).Value = Me.txtDoj.Value
                .Offset(RowCount, 5).Value = Me.txtAT.Value
                .Offset(RowCount, 6).FormulaR1C1 = _
                    "=IF(ISERROR(VLOOKUP(RC[10],BACKGROUND!C[3]:C[6],4,FALSE)=TRUE),"""",VLOOKUP(RC[10],BACKGROUND!C[3]:C[6],4,FALSE))"
                .Offset(RowCount, 7).Value = Me.txtSC.Value
                .Offset(RowCount, 8).Value = Me.txtMC.Value
                .Offset(RowCount, 9).Value = Me.cmbAct.Value
                .Offset(RowCount, 10).Value = Me.txtWk.Value
                .Offset(RowCount, 11).Value = Me.cmbPN.Value
                .Offset(RowCount, 12).Value = Me.cmbFac.Value
                .Offset(RowCount, 13).Value = Me.txtBT.Value
                .Offset(RowCount, 14).Value = Me.txtPC.Value
                .Offset(RowCount, 15).Value = Me.txtStock.Value
                .Offset(RowCount, 16).Value = Me.txtJobdesc.Value
            End With
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0