Results 1 to 3 of 3

Loop to find, copy and paste data doesn't work

Threaded View

  1. #1
    Registered User
    Join Date
    02-13-2012
    Location
    Oshkosh, WI
    MS-Off Ver
    Excel 2010
    Posts
    2

    Loop to find, copy and paste data doesn't work

    Hello All,

    I'm trying to find information in a second spreadsheet that matches information from the first and then return the found values back to the first spreadsheet. The problem is it doesn't seem to be looping through all of the data in the second spreadsheet. The code looks like this...
    Sub Calculate()
    
    Dim I As Integer
    Dim RowOff As Integer
    Dim Machine As Range
    
    I = 0
    RowOff = 0
    
    Set Machine = Range("B2")
    
    Select Case Machine
        Case "21"
            Sheets(1).Range("B3:B4").Copy
            Sheets("21").Activate
            Range("L1:L2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            ActiveSheet.Calculate
        
            For I = 1 To 160
                        If Sheets(2).Range("A2").Offset(RowOff, 0).Value = Sheets(2).Range("L1").Value Then
                        If Sheets(2).Range("L2").Value >= Sheets(2).Range("B2").Offset(RowOff, 0).Value _
                        And Sheets(2).Range("L2").Value <= Range("C2").Offset(RowOff, 0).Value Then
                
                            Sheets(2).Range("B2:J2").Offset(RowOff, 0).Copy
                            
                            Sheets(1).Activate
                            Range("A14").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                                :=False, Transpose:=False
                            
                            Exit For
                            Else
                        
                        End If
                    
                        End If
                        
                Count = Count + 1
                RowOff = RowOff + 1
           Next I
           Sheets(1).Activate
           
    End Select
        
    Application.CutCopyMode = False
    
    End Sub
    ]Scheduling Tool.xlsm
    I've also attached the spreadsheet. I hope to be able to take this code and apply it to a much larger data set. Let me know If you need any more information, any and all help is appreciated.
    Last edited by mazerinth; 02-13-2012 at 01:26 PM.

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