+ Reply to Thread
Results 1 to 3 of 3

UserForm_Initialize() and set up the worksheets

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-04-2014
    Location
    Netherlands
    MS-Off Ver
    all
    Posts
    121

    Smile UserForm_Initialize() and set up the worksheets

    Hi,

    What is the best way set up the sheets when working with forms?
    I don't like to set up the sheets all the time..there must be an easier way right?

    Private Sub UserForm_Initialize()
                 Dim TheSheet_A as Worksheet
                 Set TheSheet_A= Sheets("_A")
    
                 Dim TheSheet_B As Worksheet
                 Set TheSheet_B = Sheets("B")
                 
                 Dim TheSheet_C As Worksheet
                 Set TheSheet_C = Sheets("C")
    
    End Sub
    
    Private Sub UserForm_Initialize()
        
    Call needWorkSheets(TheSheet_A)
    or
    Call setupTheWorkSheets
    
    
    End Sub

    
    Private Function needWorkSheets(ws) as String
    with ws
    End with
    End Function
    
    
    Private Function setupTheWorkSheets ()
                 Dim TheSheet_A as Worksheet
                 Set TheSheet_A= Sheets("_A")
    
                 Dim TheSheet_B As Worksheet
                 Set TheSheet_B = Sheets("B")
                 
                 Dim TheSheet_C As Worksheet
                 Set TheSheet_C = Sheets("C")
    
    End Function
    Last edited by mreFF; 07-06-2014 at 12:48 PM.

  2. #2
    Forum Contributor
    Join Date
    07-04-2014
    Location
    Netherlands
    MS-Off Ver
    all
    Posts
    121

    Re: UserForm_Initialize() and set up the worksheets

    When reading or adding data to it, you allways have to use Worksheets("Sheet2").Select ?

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: UserForm_Initialize() and set up the worksheets

    When reading or adding data to it, you allways have to use Worksheets("Sheet2").Select ?
    No, you can change cell values without activating the sheet

    Sheets("Sheet1").Select
    Range("A3").Select
    Selection.Value = "Hello"
    can be done (faster, more reliably and easier) by
    Sheets("Sheet1").Range("A3").Value = "Hello"
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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. VBA combobox UserForm_Initialize
    By Hilton1982 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-03-2012, 08:55 AM
  2. Userform_initialize event
    By rajeev.raj in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-23-2012, 03:07 AM
  3. Set Me.Picture on UserForm_Initialize
    By mpeplow in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-13-2007, 05:49 PM
  4. [SOLVED] UserForm_Initialize
    By RB Smissaert in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-13-2006, 11:52 AM
  5. UserForm_Initialize error
    By Jennifer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2005, 05:07 PM

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