• Copy to New Spreadsheet brings empty column Label

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Copy to New Spreadsheet brings empty column Label

    Author
    Topic
    #459675

    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]

    Viewing 0 reply threads
    Author
    Replies
    • #1159710

      You could include a test for the row #:

      If n>6 Then
      ‘Copy code goes here
      End If

      • #1159788

        You could include a test for the row #:

        If n>6 Then
        ‘Copy code goes here
        End If

        Thanks Pieterse, great suggestion

    Viewing 0 reply threads
    Reply To: Copy to New Spreadsheet brings empty column Label

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: