Can't seem to get the ranges to work

Darren Smith

Active Member
Joined
Nov 23, 2020
Messages
370
Office Version
  1. 2019
Platform
  1. Windows
This code has 2 sets of ranges both don't seem to work? The SrcDataRange & DesDataRange
One is Destination workbook other is Source workbook?

VBA Code:
Sub Job_Record_Detail()

Application.ScreenUpdating = False
 


    Dim Src As Workbook
    Dim SrcOpen As Workbook
    Dim Des As Workbook
    Dim JCM As Worksheet
    Dim TGSR As Worksheet
    Dim FilePath As String
    Dim Filename As String
    Dim DesDataRange As Range
    Dim SrcDataRange As Range
 

    FilePath = "\\TGS-SRV01\Share\ShopFloor\PRODUCTION\JOB BOOK\"
    Filename = "JOB RECORD SHEET.xlsm"
 
    Set Des = Workbooks("Automated Cardworker.xlsm")
    Set JCM = Worksheets("Job Card Master")
    Set SrcOpen = Workbooks.Open(FilePath & Filename)
    Set Src = Workbooks("JOB RECORD SHEET.xlsm")
    Set TGSR = Worksheets("TGS JOB RECORD")
 
    Set SrcDataRange = Workbooks(Src).Worksheets(TGSR).Range("A2:NA").Select
 
    Set DesDataRange = Workbooks(Des).Worksheets(JCM).Range("A2:Q").Select

    DesDataRange("A4").Value = Application.WorksheetFunction.VLookup(DesDataRange("G4"), Range("SrcDataRange"), 40, 0)
    Columns("A:Q").EntireColumn.AutoFit
    Range("A4").Select


         
    Src.Close
         
     Application.ScreenUpdating = True
         
         
 
    End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,526
Office Version
  1. 365
Platform
  1. Windows
In that case try
VBA Code:
JCM.Range("A4").Value = Application.WorksheetFunction.VLookup(JCM.Range("G4"), SrcDataRange, 40, 0)
 
Solution

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Darren Smith

Active Member
Joined
Nov 23, 2020
Messages
370
Office Version
  1. 2019
Platform
  1. Windows
Thanks Fluff

Sorry but something is still wrong VLookup code still not working,
Error says Unable to get VLookup property of the workshopfunction class
 

Darren Smith

Active Member
Joined
Nov 23, 2020
Messages
370
Office Version
  1. 2019
Platform
  1. Windows
Thanks Fluff your a hero all working like a dream.
Ignore the above please
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,526
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,537
Messages
5,625,394
Members
416,100
Latest member
lirongr1996

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
Top