Input file to specific sheet

jules-57

Board Regular
Joined
Aug 27, 2013
Messages
88
The below code works fine for generic applications.

What if I wanted to input a file on the desktop to a specific sheet named "RAW SCORES"

This seems to be the line in question along with some DIM variable???: targetSheet.Range("B2:B31").Value = sourceSheet.Range("B2:B31").Value

This seems to be simple, but alludes novices like myself

Thanks for any help!

======================

' Get customer workbook
Dim customerBook As Workbook
Dim filter As String
Dim caption As String
Dim customerFilename As String
Dim customerWorkbook As Workbook
Dim targetWorkbook As Workbook

' make weak assumption that active workbook is the target
Set targetWorkbook = Application.ActiveWorkbook

' get the customer workbook
filter = "Text files (*.csv),*.csv"
caption = "Please Select an input file "
customerFilename = Application.GetOpenFilename(filter, , caption)

Set customerWorkbook = Application.Workbooks.Open(customerFilename)

' assume range is B2 - B31 in sheet1

' copy data from customer to target workbook
Dim targetSheet As Worksheet
Set targetSheet = targetWorkbook.Worksheets(1)
Dim sourceSheet As Worksheet
Set sourceSheet = customerWorkbook.Worksheets(1)

targetSheet.Range("B2:B31").Value = sourceSheet.Range("B2:B31").Value


' Close customer workbook
customerWorkbook.Close
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
What if I wanted to input a file on the desktop to a specific sheet named "RAW SCORES"

The question is elusive.

Do you want to reference a sheet named "RAW SCORES" instead of Worksheets(1)?

If yes, try this...

Set sourceSheet = customerWorkbook.Worksheets("RAW SCORES")
 
Upvote 0

Forum statistics

Threads
1,202,958
Messages
6,052,791
Members
444,602
Latest member
Cookaa

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