+ Reply to Thread
Results 1 to 5 of 5

Creating a copy, paste, print Loop VBA

Hybrid View

evian123 Creating a copy, paste, print... 09-29-2013, 11:16 AM
patel45 Re: Creating a copy, paste,... 09-29-2013, 11:24 AM
evian123 Re: Creating a copy, paste,... 09-29-2013, 11:32 AM
HaHoBe Re: Creating a copy, paste,... 09-29-2013, 11:43 AM
evian123 Re: Creating a copy, paste,... 09-29-2013, 12:10 PM
  1. #1
    Registered User
    Join Date
    09-29-2013
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    3

    Creating a copy, paste, print Loop VBA

    Hi,

    I am trying to create a macro that will cycle through cells and print certain ranges dependant upon vlookups, it is essentially a primative certificate generator as im not much use with excel

    So far i have this code:

    Sub Shortway()
        For Each c In Worksheets("Generator").Range("P6:P26").Cells
             
        Range(c.Value).Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("P1").Select
        ActiveSheet.Paste
        
            If Range("T15").Value = "X" Then
            Range("A2:L61").PrintOut
            End If
            
            If Range("T16").Value = "X" Then
            Range("A63:L122").PrintOut
            End If
            
            If Range("T17").Value = "X" Then
            Range("A124:L183").PrintOut
            End If
            
            If Range("T18").Value = "X" Then
            Range("A185:L244").PrintOut
            End If
            
            If Range("T19").Value = "X" Then
            Range("A246:L305").PrintOut
            End If
            
            If Range("T20").Value = "X" Then
            Range("A307:L366").PrintOut
            End If
            
        Next
    
    End Sub
    I butchered some i found on the internet and inserted my copy and if statements; not sure why its not working!

    Any help appreciated!

    Thanks,

    James,
    Last edited by evian123; 09-29-2013 at 12:02 PM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Creating a copy, paste, print Loop VBA

    very confused code, attach please a sample file with data and desired result
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    09-29-2013
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Creating a copy, paste, print Loop VBA

    I can imagine! im not very experienced with macros!

    please find an attached file...

    The desired result is that the code cycles through the tags, populates the certificates and prints them accordingly. I already have a macro that does this for 10 as an example, but really i need it to cycle through 100s!

    Thanks,

    James,
    Attached Files Attached Files
    Last edited by evian123; 09-29-2013 at 12:12 PM.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Creating a copy, paste, print Loop VBA

    Hi, James,

    maybe proceed like this:
    Sub Shortway2()
    Dim c As Range
    
    With Worksheets("Generator")
      For Each c In .Range("P6:P26")
        .Range("P1").Value = c.Value
      
        If .Range("T15").Value = "X" Then
          .Range("A2:L61").PrintOut
        End If
          
        If .Range("T16").Value = "X" Then
          .Range("A63:L122").PrintOut
        End If
          
        If .Range("T17").Value = "X" Then
          .Range("A124:L183").PrintOut
        End If
          
        If .Range("T18").Value = "X" Then
          .Range("A185:L244").PrintOut
        End If
          
        If .Range("T19").Value = "X" Then
          .Range("A246:L305").PrintOut
        End If
          
        If .Range("T20").Value = "X" Then
          .Range("A307:L366").PrintOut
        End If
          
      Next c
    End With
    End Sub
    And if you want to loop through the cells for a check if to print:
    Sub Shortway3()
    Dim c As Range
    Dim lngCounter As Long
    Dim lngHelp As Long
    
    With Worksheets("Generator")
      For Each c In .Range("P6:P26")
        .Range("P1").Value = c.Value
        For lngCounter = 15 To 20     'alter here
          If .Range("T" & lngCounter).Value = "X" Then
            lngHelp = lngCounter - 15
            .Range("A" & 2 + lngHelp * 61 & ":L" & 61 + lngHelp * 61).PrintOut
          End If
        Next lngCounter
      Next c
    End With
    End Sub
    Ciao,
    Holger
    Last edited by HaHoBe; 09-29-2013 at 11:47 AM.
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  5. #5
    Registered User
    Join Date
    09-29-2013
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Creating a copy, paste, print Loop VBA

    Thanks so much!!!!

+ 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. [SOLVED] Creating a Macro Loop to copy & paste several lines
    By homike2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-05-2013, 07:10 PM
  2. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  3. Copy&paste Print loop help please
    By avit in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-17-2011, 09:09 AM
  4. Copy&paste Print loop help please
    By avit in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-17-2011, 09:05 AM
  5. Creating a loop that will sort, copy, paste and save data into seperate workbooks
    By EggHead in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-14-2009, 03:17 PM

Tags for this Thread

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