+ Reply to Thread
Results 1 to 5 of 5

Error "Subscript out of range", cant seem to find where code is wrong

Hybrid View

  1. #1
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Error "Subscript out of range", cant seem to find where code is wrong

    perhaps
    Sub SummarySheetPasteTest()
    Dim RunNo As String, strPath As String, SourceFile As String
    Dim wsWafer As Worksheet, WaferLetter As String, increment As Integer
    
    Dim wsSummary as worksheet 
    Set wsSummary = thisworkbook.sheets("summary")
    
    RunNo = Mid(ThisWorkbook.Name, 6, 6)
    Name = ThisWorkbook.Name
    increment = 0
    
    For Each wsWafer In Sheets(Array("XRD-A", "XRD-B", "XRD-C", "XRD-D", "XRD-E", "XRD-F", "XRD-G", "XRD-H", "XRD-I", "XRD-J"))
        
            WaferLetter = Chr(65 + increment)
            WaferRow = 21 + increment
            strPath = "C:\X'Pert Data\Wafers\W" & RunNo & "\WaferXRDAnalysis" & RunNo
            SourceFile = strPath
            If SourceFile <> "" Then
                Do
                    'On Error Resume Next
                    With Workbooks.Open(Filename:=SourceFile)
                        .Sheets(WaferLetter & "-G").Range("R2").Copy Destination:=wsSummary.Range("X" & WaferRow)
                        .Sheets(WaferLetter & "-G").Range("R4").Copy Destination:=wsSummary.Range("AA" & WaferRow)
                        .Sheets(WaferLetter & "-N").Range("R2").Copy Destination:=wsSummary.Range("AF" & WaferRow)
                        .Sheets(WaferLetter & "-N").Range("R4").Copy Destination:=wsSummary.Range("AH" & WaferRow)
                    End With
                    SourceFile = "StopThisLoop"
                Loop While SourceFile <> "StopThisLoop"
            End If
            increment = increment + 1
            'MsgBox "WaferLetter is " & WaferLetter
        Next wsWafer
    End Sub
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  2. #2
    Registered User
    Join Date
    05-27-2013
    Location
    Buellton, California
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Error "Subscript out of range", cant seem to find where code is wrong

    Yes, arlu1201 "Name" is where the data is going.

    Quote Originally Posted by JosephP View Post
    perhaps
    Sub SummarySheetPasteTest()
    Dim RunNo As String, strPath As String, SourceFile As String
    Dim wsWafer As Worksheet, WaferLetter As String, increment As Integer
    
    Dim wsSummary as worksheet 
    Set wsSummary = thisworkbook.sheets("summary")
    
    RunNo = Mid(ThisWorkbook.Name, 6, 6)
    Name = ThisWorkbook.Name
    increment = 0
    
    For Each wsWafer In Sheets(Array("XRD-A", "XRD-B", "XRD-C", "XRD-D", "XRD-E", "XRD-F", "XRD-G", "XRD-H", "XRD-I", "XRD-J"))
        
            WaferLetter = Chr(65 + increment)
            WaferRow = 21 + increment
            strPath = "C:\X'Pert Data\Wafers\W" & RunNo & "\WaferXRDAnalysis" & RunNo
            SourceFile = strPath
            If SourceFile <> "" Then
                Do
                    'On Error Resume Next
                    With Workbooks.Open(Filename:=SourceFile)
                        .Sheets(WaferLetter & "-G").Range("R2").Copy Destination:=wsSummary.Range("X" & WaferRow)
                        .Sheets(WaferLetter & "-G").Range("R4").Copy Destination:=wsSummary.Range("AA" & WaferRow)
                        .Sheets(WaferLetter & "-N").Range("R2").Copy Destination:=wsSummary.Range("AF" & WaferRow)
                        .Sheets(WaferLetter & "-N").Range("R4").Copy Destination:=wsSummary.Range("AH" & WaferRow)
                    End With
                    SourceFile = "StopThisLoop"
                Loop While SourceFile <> "StopThisLoop"
            End If
            increment = increment + 1
            'MsgBox "WaferLetter is " & WaferLetter
        Next wsWafer
    End Sub
    Thanks JosephP, that worked!
    It copied the format of the cells in the source workbook though (green cell) is there a way to do paste special > values within the .copy destination:= part?

+ 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