+ Reply to Thread
Results 1 to 2 of 2

Selective Copy to 2 different templates based on value in column L or R or Both.

Hybrid View

corneliusj Selective Copy to 2 different... 09-14-2014, 12:47 PM
xladept Re: Selective Copy to 2... 09-14-2014, 06:51 PM
  1. #1
    Registered User
    Join Date
    07-20-2014
    Location
    Egypt
    MS-Off Ver
    2010
    Posts
    4

    Selective Copy to 2 different templates based on value in column L or R or Both.

    Good evening guys. I spent a lot of time working on an Excel Report that generates Installation Cards based on counting the rows in the schedule (which is an output from a Design Application) and creating individual sheets with the specific data from each row. However, today the guys asked that it should instead generate 2 different templates based on values in Column L or R, and in cases where both are completed, to generate both the cards. Currently, I was thinking a simple IF selection could do the trick, but I am not sure where exactly to start it from. The code for a single template looks as follows:

    Sub GenerateTerminationCard()
    
      'To check sheet existance
    Dim bExists As Boolean
    For i = 1 To Worksheets.Count
        If Worksheets(i).Name = "7" Then
            bExists = True
        End If
    Next i
    
    Sheets("Sheet1").Select
    
    If Worksheets("Sheet1").Range("b8").Value = "" Then
    ActiveSheet.Range("b7").Select
    Else
    ActiveSheet.Range("b7", ActiveSheet.Range("b7").End(xlDown)).Select
    End If
    
    
    Dim dNoOfTags As Double
    dNoOfTags = Selection.CountLarge
    
    
    ActiveSheet.Range("b" & dNoOfTags + 7, ActiveSheet.Range("b" & dNoOfTags + 7).End(xlDown)).EntireRow.Delete
    
    
    Dim nSelectedCells() As Integer
    ReDim nSelectedCells(dNoOfTags) As Integer
    
    For i = 1 To dNoOfTags
    nSelectedCells(i) = i
    Next
    
    If bExists = False Then
    
      'Copying Termination Card sheets and rename
    
    Application.ScreenUpdating = False
    
    Sheets("Termination Card").Visible = True
    
     For i = 1 To dNoOfTags
    
    
    Sheets("Termination Card").Copy After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
    ActiveSheet.Name = (i + 6)
    Next
    
      'Copying Cells from Sheet1 to Termination Cards
    
    
    For i = 7 To (dNoOfTags + 6)
    Worksheets("Sheet1").Range("B" & i).Copy
    Worksheets("" & i & "").Select
    Worksheets("" & i & "").Range("A8").Select
    Worksheets("" & i & "").PasteSpecial xlPasteValuesAndNumberFormats
    Worksheets("" & i & "").Range("A35").Select
    Worksheets("" & i & "").PasteSpecial xlPasteValuesAndNumberFormats
    Worksheets("" & i & "").Range("D54").Select
    Worksheets("" & i & "").PasteSpecial xlPasteValuesAndNumberFormats
    
     'Worksheets("Sheet1").Range("X" & i).Copy
     'Worksheets("" & i & "").Select
     'Worksheets("" & i & "").Range("F8").Select
     'Worksheets("" & i & "").PasteSpecial xlPasteValuesAndNumberFormats
    
     'there are a lot more rows being copied but I removed for now
    
    Next
    Sheets("Termination Card").Visible = False
    
    Else
    
    Application.DisplayAlerts = False
    For i = 7 To dNoOfTags + 6
    Sheets("" & i & "").Select
    ActiveWindow.SelectedSheets.Delete
    Next i
    Application.DisplayAlerts = True
    
    End If
    
    
    End Sub

    I have already created the necessary Templates as sheets (named "Termination Card FROM" and "Termination Card TO" respectively).

    Any help or advice would be greatly appreciated.
    Last edited by corneliusj; 09-14-2014 at 10:59 PM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Selective Copy to 2 different templates based on value in column L or R or Both.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ 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. Selective column copy...any help please???
    By samuella in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-30-2014, 06:07 PM
  2. Copy data from one sheet to another based on selective criteria
    By jnmturner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2013, 05:30 AM
  3. Copy selective rows to another worksheet based on single column within origin workshe
    By ianaseltine in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-23-2012, 01:54 PM
  4. -- Selective Cut and Paste -- Cut and Paste based off of B Column's Content --
    By brad70989 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-09-2011, 03:29 PM
  5. Copy selective data
    By herolindl in forum Excel General
    Replies: 5
    Last Post: 07-07-2010, 02:10 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