Results 1 to 11 of 11

userform for printing

Threaded View

  1. #8
    Forum Contributor wamp's Avatar
    Join Date
    11-10-2008
    Location
    Norway
    MS-Off Ver
    97, 2000 & 2003 (diff. workstations)
    Posts
    184

    Re: userform for printing

    ok.. let's simplify; or clarify what to do here.. you want to do the following:
    * Create a new sheet from one of two templates, based on name in a cell value
    * rename the new template according to column C:E (not specified which row??)

    have a look at the following code (untested) and see if you can use that.
    Since you never specified the row, the macro takes hold of the row you've currently selected

    Sub test()
    Dim rValue As Integer  ' create an integer value called rValue
    rValue = ActiveCell.Row ' set rValue to the number of the row you're in
    
    Dim templateSelect As String
    templateSelect = Sheet1.Range("E" & rValue).Value   ' stores the name of the cell in a variable
    Dim sheetName As String 'the name of the sheet to be created
    sheetName = Sheet1.Range("C" & rValue).Value & " " & Sheet1.Range("D" & rValue).Value & " " & Sheet1.Range("E" & rValue).Value  ' sets the name
    msgbox (sheetName)  'A messagebox just for you to see what the sheetname will be based on the above line of code.  Comment out this later on after fiddlin' with the code.
    
    ' we assume that column E always contains only Motor, Contractor or other (Motor + Contractor) to determine which template to call
    
    '** now to check which template to use***
    If templateSelect = "Motor" Then GoTo motor
    If templateSelect = "Contractor" Then GoTo contractor
    'if none above is correct, it must correspond to "Motor + Contractor" and the code for that template should go here.
    MsgBox ("Motor + Contractor code not yet selected template")
    Exit Sub
    
    motor:
    Sheets("NAME OF MOTOR TEMPLATE HERE").Select
    Sheets("NAME OF MOTOR TEMPLATE HERE").Copy Before:=Sheets(2)
    Sheets("NAME OF MOTOR TEMPLATE HERE (2)").Name = (sheetName)
    Exit Sub
    
    contractor:
    Sheets("NAME OF CONTRACTOR TEMPLATE HERE").Select
    Sheets("NAME OF CONTRACTOR TEMPLATE HERE").Copy Before:=Sheets(2)
    Sheets("NAME OF CONTRACTOR TEMPLATE HERE (2)").Name = (sheetName)
    Exit Sub
    
    
    End Sub
    Last edited by wamp; 04-19-2010 at 07:18 AM. Reason: spelling errors

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