Consulting

Results 1 to 18 of 18

Thread: Run time error 91 object variables not set

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Sep 2023
    Posts
    6
    Location

    Unhappy Run time error 91 object variables not set

    Hi,

    I've been trying to figure out what could be wrong with my code. I tried all I can search to update the code seems the same error.

    This are my code

    Sub Consolidate ()
    
    On error GoTo 0
    Dim Destrange as range
    Dim DestWB as workbook
    Dim DestSh as worksheet
    Dim Lr as long
    With application
    . ScreenUpdating = False
    . EnableEvents = False
    End with 
    If bISBookOpen_RB("pathfolder.xlsx" ) Then
     Set DestWB = Workbooks(" pathfolder.xlsx") 
    Else
     Set DestWB = Workbooks.Open("pathfolder.xlsx")
    End If
    Set ws1 = This Workbook.ActiveSheet
    Set rg1 = ws1.Range ("A2:K2") 
    Set DestWB = Workbooks.Open("pathfolder.xlsx")
         Lr = Last(1, DestRange) 
    Set DestRange = DestSh.Range("A" & DestWB.Worksheets("Data").Rows.Count.End(xlUp)
    Set DestSh = Dest.Range("A2") 
    Do until IsEmpty(DestSh) 
        Set DestSh = DestRange.offset(1, 0)
    Loop
    With Rg1
    . Select
    . Copy
    Endwith
    With DestSh 
     DestRange.PasteSpecial _
                Paste:=xlPasteValues, _
                operation:=xlPasteSpecialOperationNone, _
                skipblanks:=False, _
                Transpose:=False
    End With
    Else
    End If
    Exit Sub
    DestWB.Close Savechanges:= True
    With application
    . ScreenUpdating = True
    . EnableEvents = True
    End With
    End Sub
    With this code
    Set DestRange = DestSh.Range("A" & DestWB.Worksheets("Data").Rows.Count.End(xlUp)
    Set DestSh = Dest.Range("A2")
    This two is highlighted in yellow and shows DestRange=Nothing DestSh = nothing

    Your help will be highly appreciated

    Thank you in advance
    Last edited by Paul_Hossler; 09-12-2023 at 04:56 PM.

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
  •