+ Reply to Thread
Results 1 to 2 of 2

creating form to select worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    11-23-2012
    Location
    Vacnouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    creating form to select worksheet

    Hi

    I have the following code that copys selected cells into a worksheet called "Feb" in a workbook called "sample_tracking_2013"

    Dim wbb As Workbook
    For Each wbb In Workbooks
    If wbb.Name = "Sample_Tracking_2013.xlsx" Then GoTo Setwss
    Next
    Workbooks.Open _
    Filename:="C:\BralorneProject\Geology\Admin\2013 Admin\Sample Tracking\sample_tracking_2013.xlsx"
    wa.Activate
    Setwss:
    Set wbb = Workbooks("Sample_Tracking_2013")
    Set wss = wbb.Worksheets("Feb")
    s = wss.Range("A" & Rows.Count).End(xlUp).Row + 1
    ThisWorkbook.Activate
    Selection.Copy: wss.Range("A" & s).PasteSpecial xlPasteValues
    wbb.Close True
    End Sub
    There are several worksheets within the work book and i want the macro to ask which sheet i want to paste the data into, instead of pasting the data into the "Feb" work sheet.

    Cheers
    Eric

  2. #2
    Forum Contributor
    Join Date
    10-19-2012
    Location
    Omaha, Nebraska USA
    MS-Off Ver
    Excel 2010
    Posts
    249

    Re: creating form to select worksheet

    Hi Eric,

    Here is the code I added to provide a userform that lists worksheet names in an active workbook. I ran it using my own paths and it seems to work, but I set it back to what you had with my code added, so hopefully this gets you on the right track. The excel file attached has this code and also has the code for the userform.

    ' START of ADDED CODE
    Option Explicit
    
    Public nSheet() As String
    Public i As Long
    Public uSheet As String
    Public cSheet As Long
    ' END of ADDED Code
    
    Sub PasteData()
    
    Dim s As Long
    Dim wss As Worksheet
    Dim wa As Workbook
    Dim wbb As Workbook
    
    Set wa = ActiveWorkbook
    cSheet = Sheets.Count
    
    For Each wbb In Workbooks
       If wbb.Name = "Temp.xls" Then GoTo Setwss
       If wbb.Name = "Sample_Tracking_2013.xlsx" Then GoTo Setwss
    Next
    Workbooks.Open _
    Filename:="C:\BralorneProject\Geology\Admin\2013 Admin\Sample Tracking\sample_tracking_2013.xlsx"
    wa.Activate
    Setwss:
    Set wbb = Workbooks("Sample_Tracking_2013")
    
    ' START of ADDED CODE (Populate Worksheet Names)
       wa.Activate
       ReDim nSheet(1 To Sheets.Count) As String
       For i = 1 To cSheet
          nSheet(i) = Sheets(i).Name
       Next i
       ' Call Userform
       frmSheetList.Show
    ' END of ADDED CODE
    
    Set wss = wbb.Worksheets(uSheet)
    s = wss.Range("A" & Rows.Count).End(xlUp).Row + 1
    ThisWorkbook.Activate
    Selection.Copy: wss.Range("A" & s).PasteSpecial xlPasteValues
    wbb.Close True
    End Sub
    Thanks,

    Daniel
    Attached Files Attached Files

+ Reply to 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