copy and past one file to multi file.

faizan haq

New Member
Joined
Jan 14, 2020
Messages
12
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
  2. MacOS
Hi,

I have unique value in A1:A10 in master 1 file and i need to paste one by one value into multiple files which is available in folder it should be done by VBA automatic,

all work on sheet1
step
1. copy (A1) value from master file
2. open 1 file from folder
3. paste on (B10)
4. save and close
5. copy (A2) value from master file
6. open 2 file from folder
7. paste on (B10)
8. save and close


Valueneed to paste value in multi files and cell range is common (B10)
CO11 filenam.xls
CO22 filenam.xls
CO33 filenam.xls
CO44 filenam.xls
CO55 filenam.xls
CO66 filenam.xls
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi and welcome to MrExcel!

Try this, You put the macro file in the same folder where the files are..

VBA Code:
Sub copy_value_in_file()
  Dim i As Long, sPath As String, sFile As String, sh As Worksheet
  Application.ScreenUpdating = False
  
  Set sh = ActiveSheet
  sPath = ThisWorkbook.Path & "\"
  For i = 1 To 10
    sFile = Range("B" & i).Value
    If sFile <> "" And Dir(sPath & sFile) <> "" Then
      Workbooks.Open (sPath & sFile)
      Range("B10").Value = sh.Range("A" & i).Value
      ActiveWorkbook.Close True
    End If
  Next
End Sub
 
Upvote 0
Hi Dante,

thanks for reply. but showing error, i want to more clarify that what i want. please check attached file and advice accordingly.
 

Attachments

  • Screen Shot copy.jpg
    Screen Shot copy.jpg
    171.8 KB · Views: 4
Upvote 0
You put the macro file in the same folder where the files are..

the file name with extension you must put it in column B. So you asked for it in your original post.

Please: Do not modify the macro.
 
Upvote 0
Hi,
Great its working, its is possible that we dont need to paste file name in excel column B, its run by auto?
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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