Results 1 to 10 of 10

Error msgs: "Object varible or with block variable not set"; "subscript out of range"

Threaded View

  1. #1
    Registered User
    Join Date
    10-25-2009
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    14

    Error msgs: "Object varible or with block variable not set"; "subscript out of range"

    The following macro gives me two types of error messages:
    "object variable or with block variable not set" or "subscript out of range" on the first or the second line valFoundRow=...
    And I could not understand why...
    What I am trying to do is delete a couple of rows with unnecessary information, then copy the rest in different columns, not in one as they are now. I have no problem with the second part of the macro - it worked just fine before I added the part where the rows, containing "Share", "Save", "Email a Friend", "TRUE and the empty rows are supposed to be deleted.

    If anyone could help me with that, I would be really grateful...

    Sub Macro2()
    '
    ' Macro2 Macro
    ' Macro recorded 24.10.2009 by MID
    '
    
     Dim searchSheet As String, searchCol As Integer, valFoundRow As Integer, z As Integer, y As Integer, w As Integer, u As Integer, a As Integer, b As Integer, c As Integer, d As Integer
     
     
        Application.ScreenUpdating = False
    searchSheet = "Sheet1"
        searchCol = 1
    
               
    valFoundRow = Sheets(searchSheet).Columns(searchCol).Find(What:="Share", LookIn:=xlFormulas, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=True, SearchFormat:=False).Row
        
      x = 1
    
     For x = 1 To 5000
       Worksheets("Sheet1").Rows(valFoundRow).Delete Shift:=xlUp
     Next x
       
       Application.Calculation = xlCalculationManual
    
        Application.ScreenUpdating = False
       searchSheet = "Sheet1"
        searchCol = 1
    
               
     valFoundRow = Sheets(searchSheet).Columns(searchCol).Find(What:="TRUE", LookIn:=xlFormulas, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=True, SearchFormat:=False).Row
         
        z = 1
       For z = 1 To 5000
           Worksheets("Sheet1").Rows(valFoundRow).Delete Shift:=xlUp
       Next z
        Application.Calculation = xlCalculationManual
    
        Application.ScreenUpdating = False
         searchSheet = "Sheet1"
        searchCol = 1
    
         valFoundRow = Sheets(searchSheet).Columns(searchCol).Find(What:="", LookIn:=xlFormulas, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=True, SearchFormat:=False).Row
         
          y = 1
         For y = 1 To 5000
         Worksheets("Sheet1").Rows(valFoundRow).Delete Shift:=xlUp
         Next y
         Application.Calculation = xlCalculationManual
    
        Application.ScreenUpdating = False
        
         
         searchSheet = "Sheet1"
        searchCol = 1
     
          valFoundRow = Sheets(searchSheet).Columns(searchCol).Find(What:="Email a Friend", LookIn:=xlFormulas, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=True, SearchFormat:=False).Row
          
         w = 1
         For w = 1 To 5000
          Worksheets("Sheet1").Rows(valFoundRow).Delete Shift:=xlUp
      Next w
      Application.Calculation = xlCalculationManual
    
        Application.ScreenUpdating = False
     
       searchSheet = "Sheet1"
        searchCol = 1
    
       valFoundRow = Sheets(searchSheet).Columns(searchCol).Find(What:="Save", LookIn:=xlFormulas, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=True, SearchFormat:=False).Row
          
          u = 1
      For u = 1 To 5000
      
           Worksheets("Sheet1").Rows(valFoundRow).Delete Shift:=xlUp
             
     Next u
       Application.Calculation = xlCalculationManual
    
        Application.ScreenUpdating = False
    
       a = 1
       
        For z = 1 To 1500
        Worksheets("Sheet1").Range("A" & a).Copy
        a = a + 4
        
     
     searchSheet = "Sheet2"
        searchCol = 8
    
               
        valFoundRow = Sheets(searchSheet).Columns(searchCol).Find(What:="", LookIn:=xlFormulas, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=True, SearchFormat:=False).Row
          Worksheets("Sheet2").Range("H" & valFoundRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
           
           Next z
     Application.Calculation = xlCalculationManual
    
        Application.ScreenUpdating = False
       b = 2
       
        For z = 1 To 1500
        Worksheets("Sheet1").Range("A" & b).Copy
        b = b + 4
        
       searchSheet = "Sheet2"
        searchCol = 6
    
               
        valFoundRow = Sheets(searchSheet).Columns(searchCol).Find(What:="", LookIn:=xlFormulas, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=True, SearchFormat:=False).Row
          Worksheets("Sheet2").Range("F" & valFoundRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            
        
        Next z
        
     Application.Calculation = xlCalculationManual
    
        Application.ScreenUpdating = False
       c = 3
       
        For z = 1 To 1500
        Worksheets("Sheet1").Range("A" & c).Copy
        c = c + 4
       searchSheet = "Sheet2"
        searchCol = 2
    
               
        valFoundRow = Sheets(searchSheet).Columns(searchCol).Find(What:="", LookIn:=xlFormulas, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=True, SearchFormat:=False).Row
          Worksheets("Sheet2").Range("B" & valFoundRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            
        
        Next z
        Application.Calculation = xlCalculationManual
    
        Application.ScreenUpdating = False
     
       d = 4
       
        For z = 1 To 1500
        Worksheets("Sheet1").Range("A" & d).Copy
        d = d + 4
       searchSheet = "Sheet2"
        searchCol = 7
    
               
        valFoundRow = Sheets(searchSheet).Columns(searchCol).Find(What:="", LookIn:=xlFormulas, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=True, SearchFormat:=False).Row
          Worksheets("Sheet2").Range("G" & valFoundRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    
        Next z
        
        Application.Calculation = xlCalculationManual
    
        Application.ScreenUpdating = False
        
    '  Macro2 Macro
    ' Macro recorded 24.10.2009 by MID
    '
    ' Keyboard Shortcut: Ctrl+Shift+B
    End Sub
    Last edited by menyanthe; 10-26-2009 at 05:01 PM. Reason: code tags

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