VBA vlookup different workbook and specific sheet

ce1990

New Member
Joined
Jun 2, 2020
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
Hi everyone,

I have the below code which works to look up a specific work book but I also want to tell it to go to a specific worksheet and then it pastes into a different workbook. Can someone point out where in the code I need to specify the sheet and what I need to type?

Sub filetest()
Dim FilenamePrefix As String
FilenamePrefix = VBA.Format(Date, "mmm")

Dim CSVFilename As String
CSVFilename = FilenamePrefix & "2020 Forecast Tracker - Macro Tracker"

'
Range("A1").Select
ActiveCell.Formula2R1C1 = _
"=IF('" & CSVFilename & "'!RC1:R[250]C1=""BFProg"",'" & CSVFilename & "'!RC[1]:R[249]C[1], 0)"
Columns("A:A").Select
Selection.Copy
Range("B1").Select
ActiveSheet.Paste
Range("C1").Select
ActiveSheet.Paste
Range("D1").Select
ActiveSheet.Paste
Range("E1").Select
ActiveSheet.Paste
Range("F1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.Formula2R1C1 = _
"=IF('" & CSVFilename & "'!RC1:R[249]C1=""BFProg"",'" & CSVFilename & "'!RC[3]:R[249]C[3], 0)"
Cells.Select
Cells.EntireColumn.AutoFit
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
How many workbooks do you have? what are the sheet names you want to get the data from and paste the data to?
 
Upvote 0

Forum statistics

Threads
1,215,473
Messages
6,125,012
Members
449,204
Latest member
tungnmqn90

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