Consulting

Results 1 to 3 of 3

Thread: VBA Error - Missing 4 columns Data after copying

  1. #1

    VBA Error - Missing 4 columns Data after copying

    Hi, there
    I have the macro (Samples Report) workbook for copying 1 worksheet. The data of the workbook is starting from Column A to Column BA.

    After running Macro Samples report - Testing, the data of the new worksheet is ended to Column AW instead of Column BA. Just wondering the data of cell BA2 is blank so that the data of Column AY to Column BA cannot be copied to the new worksheet.

    Would you please to review the code in the macro file and advise how to fix the error?

     'find correct area to copy        
    Dim firstRow As Long
            firstRow = tempWs.Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlNext).Row
            Dim lastRow As Long
            lastRow = tempWs.Cells(tempWs.Rows.Count, "A").End(xlUp).Row
            Dim lastCol As Long
            lastCol = tempWs.Cells(firstRow + 1, tempWs.Columns.Count).End(xlToLeft).Column 'prevent empty last column
            Set end_cell = tempWs.Cells(lastRow, lastCol)
            tempWs.Range(start_cell, end_cell).Copy
    Attached Files Attached Files

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Why not
    Workbooks.Open Filename:=FileToOpen
        Sheets(1).Copy Before:=Workbooks("Macro sample report - Testing.xlsm").Sheets(1)
        ActiveSheet.Name = "Data"
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Hi, mdmackillop
    Thanks for the reply! As the file is involved with the other, I need to check. Again, thank you for your advice!!

Tags for this Thread

Posting Permissions

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