copy value from one workbook to another

Lanfeng79

New Member
Joined
Aug 25, 2017
Messages
2
I wanted to set the file name as variable so that I can copy value from various workbooks to one workbook.

While I executed the code below, it asks for name of the file three time. But All I want is one at a time to fill three cells.

what's wrong with my code?

Thanks!

Lan
.......................................................................................................

Sub transfer()
'
' transfer Macro
'


'
Dim SourceFileName As String
Dim SF As String
SourceFileName = InputBox("Source File Name: ", "File Name Please", "Source for test.xlsx")
If Len(SourceFileName) = 0 Then Exit Sub
SF = SourceFileName


Windows("Test for transfer number.xlsm").Activate
ActiveCell.FormulaR1C1 = "='[SF]Sheet1'!R3C3"
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "='[SF]Sheet1'!R4C3"
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "='[SF]Sheet1'!R5C3"
ActiveCell.Offset(0, -2).Range("A1:C1").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Save
Windows(SF).Activate
ActiveWindow.Close
ActiveCell.Offset(8, 6).Range("A1").Select
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Code:
[COLOR=#333333]ActiveCell.FormulaR1C1 = "='[" & SF & "]Sheet1'!R3C3"[/COLOR]

Similarly for the other formulas.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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