Can't seem to get the ranges to work

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
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
 
In that case try
VBA Code:
JCM.Range("A4").Value = Application.WorksheetFunction.VLookup(JCM.Range("G4"), SrcDataRange, 40, 0)
 
Upvote 0
Solution

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Thanks Fluff

Sorry but something is still wrong VLookup code still not working,
Error says Unable to get VLookup property of the workshopfunction class
 
Upvote 0
Thanks Fluff your a hero all working like a dream.
Ignore the above please
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,638
Messages
6,120,674
Members
448,977
Latest member
moonlight6

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