Closed Thread
Results 1 to 11 of 11

one userform for multiple sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    06-23-2009
    Location
    new jersey, usa
    MS-Off Ver
    Excel 2007
    Posts
    4

    one userform for multiple sheets

    I have workbook with 12 sheets in it. each sheet is identical except that they are for each month of the year. i am using a userform to enter the data into each sheet. Each sheet will have different data. I want to be able to use the same user form on each sheet but still have them insert into the open sheet. Currently I am creating duplicates of the userform for each sheet but it gets VERY!!! tiresome and it is making the workbook VERY large (5 mb so far). For example. the first sheet is "april". i open the userform and enter the data into the userform. the userform enters the data into the sheet. now i go to sheet "may". currently I open a userform in that sheet that looks exactly the same as the userform in sheet "april" but is a completely different userform. I want to be able to use the userform from sheet "april" in sheet "may" but when in sheet "may" it inserts into sheet "may".
    Thank you so much in advance
    Last edited by chromedude; 06-23-2009 at 09:20 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: one userform for multiple sheets

    Hello chromedude,

    Welcome to the Forum!

    I would need to the see your workbook. Since 5MB exceeds the upper limit for posting a workbook, you can try zipping the file or create a another workbook with only a 2 or 3 month is in it. If both options fail, you could email the workbook to me.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-23-2009
    Location
    new jersey, usa
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: one userform for multiple sheets

    Leith Ross
    here is my spreadsheet. it is zipped. thank you so much. i will be looking forward to your reply
    chromedude
    Attached Files Attached Files

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: one userform for multiple sheets

    Hello chromedude,

    Thanks for posting a sample workbook. This should be very easy. After a quick glance, it looks like each month (worksheet and UserForm) is laid out the same. If there is some difference, please let me know.

  5. #5
    Registered User
    Join Date
    06-23-2009
    Location
    new jersey, usa
    MS-Off Ver
    Excel 2007
    Posts
    4

    Smile Re: one userform for multiple sheets

    there is no difference

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: one userform for multiple sheets

    Hello chromedude,

    One form is now used to for new sales on any worksheet. You only need to have the "New Sale" button call the "NewSale" macro. The attached worksbook has all the changes made to it.The biggest code change was to your "Finish" button. Here is the code...
    Private Sub finishbutton1_Click()
    
        Dim Ctrl As MSForms.Control
        Dim CtrlName As String
        Dim LastRow As Range
        Dim NextRow As Range
        Dim RowCount As Long
        Dim Msgs As Variant
        
        ' Check user input
         For Each Ctrl In Me.Controls
           If TypeName(Ctrl) = "TextBox" Or TypeName(Ctrl) = "ComboBox" Then
              CtrlName = Ctrl.Name
              Msgs = Switch(CtrlName = "facilitytxt1", "Please enter a Facility.", _
                            CtrlName = "Unittxt1", "Please choose a Unit Type.", _
                            CtrlName = "modeltxt1", "Please enter a Model Number.", _
                            CtrlName = "quantitytxt1", "Please enter a Quantity.", _
                            CtrlName = "ordertxt1", "Please enter a Order Total.", _
                            CtrlName = "salespersontxt1", "Please enter a Salesperson.")
             If Not IsNull(Msgs) And Ctrl.Value = "" Then
                MsgBox Msgs, vbExclamation, "New Sale Form"
                Ctrl.SetFocus
                Exit Sub
             End If
           End If
         Next Ctrl
               
       ' Write data to worksheet
        Set LastRow = Cells(Rows.Count, "E").End(xlUp)
        Set NextRow = IIf(LastRow.Row < 6, Cells(6, "E"), LastRow.Offset(1, 0))
        Set NextRow = NextRow.Resize(ColumnSize:=7)
        
        NextRow.Value = Array(Datetxt1, facilitytxt1, Unittxt1, modeltxt1, _
                              quantitytxt1, ordertxt1, salespersontxt1)
                        
       ' Clear the form
        For Each Ctrl In Me.Controls
            If TypeName(Ctrl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
                Ctrl.Value = ""
            End If
        Next Ctrl
        
        Unload Me
        
    End Sub
    Attached Files Attached Files

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: one userform for multiple sheets

    Grumpy,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.

    This could be one of the reasons why you have not received a reply. If you create a new thread for yourself, you will get several replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

Closed Thread

Thread Information

Users Browsing this Thread

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

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