+ Reply to Thread
Results 1 to 4 of 4

HELP!! Create Multiple Pages within a worksheet from another worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    05-30-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    2

    HELP!! Create Multiple Pages within a worksheet from another worksheet

    Hi All

    I have a workbook with multiple rows. I want to create multiple pages of sheet 2 based on how many rows I have in sheet 1. Then import information from each row on sheet 1 into various cells in sheet 2. Can anyone help me please. I have seen lots of thread on creating multiple sheets but I want to duplicate pages of a worksheet within itself. I am in a bit of a bind with time so any help would be grately appreciated. TIA

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: HELP!! Create Multiple Pages within a worksheet from another worksheet

    ItsAllBee,

    Something like this should work for you. It wasn't readily apparent what column in 'Sheet1' populates which fields in 'Sheet2'. You should be able to replace the text entries ("Date", "Order Ref", etc) with the actual cell references. I included how to do so as comments in the code:
    Sub tgr()
        
        Dim wsData As Worksheet
        Dim wsTemp As Worksheet
        Dim LastRow As Long
        Dim LastCol As Long
        Dim rIndex As Long
        Dim cIndex As Long
        
        Set wsData = Sheets("Sheet1")
        Set wsTemp = Sheets("Sheet2")
        
        LastRow = wsData.Cells(Rows.Count, "A").End(xlUp).Row
        If LastRow < 4 Then Exit Sub
        
        For rIndex = 4 To LastRow
            LastCol = wsData.Cells(rIndex, Columns.Count).End(xlToLeft).Column
            If LastCol > 12 Then
                wsData.Copy After:=Sheets(Sheets.Count)
                With ActiveSheet
                                         'Replace these with the cell reference that it should be
                                         '  For example, if the Date is in column E of 'Sheet1' then
                                         '  instead of "Date" it should be wsData.Cells(rIndex, "E").Value
                    .Range("E1").Value = "Date"
                    .Range("B2").Value = "Order Ref"
                    .Range("E3").Value = "Model"
                    .Range("B4").Value = "Base Operating System"
                    .Range("B5").Value = "Target Country"
                    .Range("B6").Value = "Location Code"
                    .Range("B7").Value = "SOE By"
                    For cIndex = 13 To LastCol
                        .Range("A" & cIndex - 2).Value = wsData.Cells(rIndex, cIndex).Value
                    Next cIndex
                End With
        Next rIndex
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    05-30-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: HELP!! Create Multiple Pages within a worksheet from another worksheet

    You are a God send! There was a missing End If statement but now works! Thank you so much :D

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: HELP!! Create Multiple Pages within a worksheet from another worksheet

    You're very welcome. Sorry about the missing End If, I put the code up untested

+ 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