Can`t work out why my Range on a workbook worksheet says = Nothing

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
The code below has this code saying = Nothing?
VBA Code:
 Set PLDataRange = PL.Range("A13:P" & LastRow)
??

VBA Code:
Private Sub Up_Date_Prices_Click()


    
Application.ScreenUpdating = False
    
        Dim SrcOpen As Workbook
        Dim Des As Workbook
        Dim JCM As Worksheet
        Dim PL As Worksheet
        Dim FilePath As String
        Dim Filename As String
        Dim PLDataRange As Range
        Dim LastRow As Long

        FilePath = "\\TGS-SRV01\Share\ShopFloor\PRODUCTION\PURCHASING\"
        Filename = "TGS Group Inventory Sheet - Main.xlsx"
    
       
      
        Set SrcOpen = Workbooks.Open(FilePath & Filename)
        Set PL = SrcOpen.Worksheets("Part List")
        LastRow = PL.Cells(PL.Rows.Count, "A").End(xlUp).row
        Set PLDataRange = PL.Range("A13:P" & LastRow)
        Windows("TGS Group Inventory Sheet - Main.xlsx").Visible = True
       
        Set Des = Workbooks("Automated Cardworker.xlsm")
        Set JCM = Des.Worksheets("Job Card Master")
  

        JCM.Range("O15").Value = Application.WorksheetFunction.VLookup(JCM.Range("D15"), PLDataRange, 16, 0)

      
      
      Application.DisplayAlerts = False
      
       SrcOpen.Close
      
      
      Application.DisplayAlerts = True
            
      Application.ScreenUpdating = True


          End Sub
 
But it can`t seem to open the Worksheet to Vlookup in
What does that mean? You don't open a worksheet. Are you getting an error of some kind?

When I say it's gone out of scope, I mean that the variable will have been cleared since it was declared and set within that routine. Once the routine ends, the variable doesn't exist any longer.
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
What does that mean? You don't open a worksheet. Are you getting an error of some kind?

When I say it's gone out of scope, I mean that the variable will have been cleared since it was declared and set within that routine. Once the routine ends, the variable doesn't exist any longer.
Because the debug says
VBA Code:
Debug Print Src
= Nothing &
VBA Code:
Debug Print SrcDataRange
= Nothing
I`ve been working on this earlier so it`s different as you can see below. I`ve added x variable for Rows count and
VBA Code:
on error resume next

VBA Code:
Private Sub Up_Date_Prices_Click()


    
Application.ScreenUpdating = False
    
        Dim SrcOpen As Workbook
        Dim Des As Workbook
        Dim JCM As Worksheet
        Dim Src As Worksheet
        Dim FilePath As String
        Dim Filename As String
        Dim SrcDataRange As Range
        Dim DesDataRange As Range
        Dim SrcLastRow As Long
        Dim DesLastRow As Long
        Dim x As Long
        
        On Error Resume Next
        
        FilePath = "\\TGS-SRV01\Share\ShopFloor\PRODUCTION\PURCHASING\"
        Filename = "TGS Group Inventory Sheet - Main.xlsx"
    
       
      
        Set SrcOpen = Workbooks.Open(FilePath & Filename)
     
        Set Src = SrcOpen.Worksheets("Part List").Activate
        Debug.Print Src
        SrcLastRow = Src.Cells(Src.Rows.Count, "A").End(xlUp).row
        SrcDataRange = Src.Range("E2:P" & SrcLastRow)
        Debug.Print SrcDataRange
        
        Windows("TGS Group Inventory Sheet - Main.xlsx").Visible = True
       
        Set Des = Workbooks("Automated Cardworker.xlsm")
        Set JCM = Des.Worksheets("Job Card Master")
        DesLastRow = JCM.Cells(JCM.Rows.Count, "A").End(xlUp).row
        
        For x = 13 To DesLastRow

        JCM.Range("O" & x).Value = Application.WorksheetFunction.VLookup(JCM.Range("D" & x).Value, SrcDataRange, 16, False)
    
        Next x
      
      
      Application.DisplayAlerts = False
      
       
      
      
      Application.DisplayAlerts = True
            
      Application.ScreenUpdating = True


          End Sub
 
Upvote 0
First, and most important, you shouldn't just add On Error Resume Next to your code without good reason, since it will prevent you from discovering what is wrong with your code. You should only use it to suppress expected errors and you should turn it off as soon as possible.

Second, none of those debug statements are valid, so you couldn't possibly be using them - it's Debug.Print, not Debug Print, and you don't apply it to an object, you apply it to a property of an object. Furthermore, neither of them would actually return the word Nothing even if they did work. ('Nothing' has a very specific meaning in VBA, namely that an object type variable doesn't have an object assigned to it)

So, please remove the On Error Resume Next and then tell me if you get an error message and, if so, on which line, and what is the message?
 
Upvote 0
I`ve taken Away the debug code and On error resume Next

This code below says SrcDataRange= Nothing

VBA Code:
SrcDataRange = Src.Range("E2:P" & SrcLastRow)
 
Last edited:
Upvote 0
You no longer have Set at the start of that line, which you need.
 
Upvote 0
This line says Value empty.
Also, the other line above still says = Nothing with Set at the front

VBA Code:
JCM.Range("O" & x).Value = Application.WorksheetFunction.VLookup(JCM.Range("D" & x).Value, SrcDataRange, 16, False)
 
Upvote 0
So what is the error message, and where does it occur?
 
Upvote 0
The code below says Error = Nothing
VBA Code:
Set SrcDataRange = Src.Range("E2:P" & SrcLastRow)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top