VBA: Open another workbook and find date in column of dates

TaskMaster

Board Regular
Joined
Oct 15, 2020
Messages
75
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Good afternoon,

I have a spreadsheet that holds data sorted by dates. I am wanting to open another workbook and search for the date in that column to use as a reference to pull data into my current workbook.

VBA Code:
Dim FindRow As Range
Dim FindRow1 As Range
Dim ColRef As String
Dim ColRef1 As String

Set FindRow = ThisWorkbook.Worksheets("Summary").Rows(2).Find(What:="01/11/2022", LookIn:=xlValues, LookAt:=xlWhole)
Set FinRow1 = ThisWorkbook.Worksheets("Backing Data").Columns("A").Find(What:="01/11/2022", LookIn:=xlValues)

ColRef = Split(Cells(, FindRow.Column).Address, "$")(1)
ColRef1 = FindRow1.Row

ThisWorkbook.Worksheets("Summary").Range(ColRef & "5").Value = ThisWorkbook.Worksheets("Backing Data").Range("G" & ColRef1).Value

The above works perfectly in the current spreadsheet however when trying to do this referencing another workbook using the below im getting a run time error.

VBA Code:
  With Workbooks(Worksheets("Summary").Range("AC1").Value).ActiveSheet 'Holds current worksheet name
      Set Wbk = Workbooks.Open("C:\Users\Flow\Desktop\Test\Daily Stats.xls", ReadOnly:=True) ' opens workbook to copy data from
     Set DStats = Workbooks("Daily Stats.xls").Worksheet(TName).Columns("A").Find(What:="01/11/2022", LookIn:=xlValues, LookAt:=xlWhole) ' Error here Run-time error '438': Object doesm't support this property or method
      DS = DStats.Row
      .Range(ColRef & "10").Value = Workbooks("Daily Stats.xls").Worksheet(TName).Range("G" & DS).Value
      Wbk.Close False
   End With
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

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