Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Nov 2003
    Location
    Tampa, Florida, USA
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have the following code that iterates through columns and copies the columns to another spreadsheet.
    Whenever a column is empty the column label gets copied to the new sheet even though the codes stops
    right below the label? The labels are in row 6 in the sheet I am copying from.

    [codebox]
    Set WshTarget = ThisWorkbook.Worksheets("9and3")
    WshTarget.Range("A5:AJ3000").Clear
    With WshSource
    For Lngcol = 2 To 14
    n = WshSource.Cells(WshSource.Rows.Count, Lngcol).End(xlUp).Row
    WshSource.Range(.Cells(7, Lngcol), .Cells(n, Lngcol)).Copy _
    Destination:=WshTarget.Cells(5, Lngcol - 1)
    Application.CutCopyMode = False
    Next Lngcol
    End With
    [/codebox]

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could include a test for the row #:

    If n>6 Then
    'Copy code goes here
    End If
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Star Lounger
    Join Date
    Nov 2003
    Location
    Tampa, Florida, USA
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='pieterse' post='774248' date='08-May-2009 05:29']You could include a test for the row #:

    If n>6 Then
    'Copy code goes here
    End If[/quote]

    Thanks Pieterse, great suggestion

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •