Results 1 to 3 of 3

Macro to selects data from several cells and place onto another WS

Threaded View

  1. #1
    Registered User
    Join Date
    08-11-2009
    Location
    Lancashire England
    MS-Off Ver
    Excel 2007
    Posts
    34

    Macro to selects data from several cells and place onto another WS

    Hi,

    I use a macro to copy data from fields on a sheet, and place that data into another sheet formatted for printing out. I specify which sets of data are to be selected by putting "L" in adjacent column AE.

    It works great on my single sheet, BUT I now need it to function with several worksheets, ie. Search through the collumn in each WS, and if 'L' is present then get the data and put it onto the printout sheet.

    Many thanks in advance.

    Sample in attached SS.
    This is my existing macro:

    Formula: copy to clipboard
    ' Print Labels from Detail List

    Sub Labels()

    Call AllWorksheetPivots

    Dim sh1 As Worksheet
    Dim sh2 As Worksheet
    Dim r As Integer
    Dim c As Integer
    Dim p As Integer
    Dim r1 As Integer
    Dim r2 As Integer
    Dim r3 As Integer
    Dim r4 As Integer
    Dim i As Integer
    Dim c1 As Integer

    Set sh1 = Sheets("labelData")
    Set sh2 = Sheets("LabelTemplate (4)")
    'sh2.Cells.MergeCells = False

    sh2.Cells.ClearContents

    r = 0
    c = 1
    p = 1

    For i = 4 To 5000
    If UCase(sh1.Cells(i, 16)) = "L" Then
    r = r + 1
    If r > 4 Then
    r = 1
    c = c + 1
    End If
    If c > 2 Then
    p = p + 1
    r = 1
    c = 1
    End If
    If r = 1 Then r1 = 3 + (53 * (p - 1))
    If r = 2 Then r1 = 6 + 9 + (53 * (p - 1))
    If r = 3 Then r1 = 8 + 18 + (53 * (p - 1))
    If r = 4 Then r1 = 11 + 27 + (53 * (p - 1))
    If r = 5 Then r1 = 14 + 36 + (53 * (p - 1))
    If r = 6 Then r1 = 17 + 45 + (53 * (p - 1))
    If r = 7 Then r1 = 20 + 54 + (53 * (p - 1))
    If r = 8 Then r1 = 23 + 63 + (53 * (p - 1))
    If c = 1 Then c1 = 3
    If c = 2 Then c1 = 20
    sh2.Cells(r1 + 1, c1) = sh1.Cells(i, 7)
    sh2.Cells(r1 + 1, c1 + 11) = sh1.Cells(i, 9)
    sh2.Cells(r1 + 2, c1) = sh1.Cells(i, 8)
    sh2.Cells(r1 + 3, c1) = sh1.Cells(i, 10)
    sh2.Cells(r1 + 4, c1 + 1) = sh1.Cells(i, 11)
    sh2.Cells(r1 + 4, c1 + 11) = sh1.Cells(i, 12)
    sh2.Cells(r1 + 5, c1 + 5) = sh1.Cells(i, 13)
    sh2.Cells(r1 + 5, c1 + 11) = sh1.Cells(i, 14)
    'sh2.Range(Cells(r1 + 5, c1 + 11), Cells(r1 + 5, c1 + 13)).MergeCells = True

    End If
    Next i
    'Stop
    'sh2.PrintOut
    sh2.Select
    Cells(1, 1).Select
    End Sub

    End Sub
    Attached Files Attached Files
    Last edited by Craigside; 02-01-2016 at 01:33 PM. Reason: Improve clarity of my request/description

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 6
    Last Post: 12-16-2014, 09:27 AM
  2. Replies: 3
    Last Post: 09-17-2013, 10:45 PM
  3. [SOLVED] Macro to get/copy data from multiple secondary sheets to main sheet
    By CaatalyyN616 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-29-2012, 04:22 AM
  4. Macro code to pull the data from different sheets to main sheet
    By Shanthuday in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2012, 09:54 AM
  5. Macro code to pull data from different sheets based on the header of the main sheet
    By Shanthuday in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-21-2012, 05:00 AM
  6. Macro to transfer data from main sheet to sub sheets
    By sandbach in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-02-2010, 05:42 PM
  7. Amend macro to run through all sheets except two
    By rajsa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-05-2009, 11:30 AM

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