+ Reply to Thread
Results 1 to 2 of 2

Formula to copy data to new sheet works but gives an error when run

Hybrid View

bm1 Formula to copy data to new... 04-08-2010, 11:41 AM
excelxx Re: Formula to copy data to... 04-12-2010, 03:34 PM
  1. #1
    Registered User
    Join Date
    03-21-2010
    Location
    Dorset, england
    MS-Off Ver
    Excel 2007
    Posts
    16

    Formula to copy data to new sheet works but gives an error when run

    I am using a macro to copy data from multiple sheets referenced in a list of cells and place the data it one master sheet.

    The formula works and gives me the output i want however every time i run it it finishes with an error of 'Subscript out of range'

    Here is the code i'm using

    Sub blanktemp()
    
    Dim cell As Range
    lastRef = Cells(Rows.Count, 24).End(xlUp).Row
    
    For Each sheetRef In Range("X2:X" & lastRef)
    
        Sheets(sheetRef.Value).Select
        lastTest = Cells(Rows.Count, 2).End(xlUp).Row
        Range("A2:F" & lastTest).Copy
        
        Sheets("BlankTemplate").Select
        blankRow = Cells(Rows.Count, 2).End(xlUp).Row + 1 'use column 2 as at the mo nothing is in column1
        Cells(blankRow, 1).Select 'location to paste column 2, next empty row
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False   
    
    Next sheetRef
    
    End Sub
    Any help to fix the error would be apprciated

  2. #2
    Forum Contributor
    Join Date
    02-04-2010
    Location
    Hertfordshire, England
    MS-Off Ver
    Office 2007 (home) Office 365 (work)
    Posts
    134

    Re: Formula to copy data to new sheet works but gives an error when run

    Hi bm1

    I think you may have a value in the last row of Column X which is not a sheet name in your workbook. Or you are reading a blank cell from the last row of Column X.

    I hope this helps.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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