'VBA script that opens windows explorer and points to a file that copies values from one workbook to another
I have a VBA script that copies and paste data from one workbook to another, but I would like to get my script so when I click run, windows explorer window opens up and I select the file that has the data in it. It takes that data and copies and paste the data to another workbook. Some of my cells don't need to get pasted over to the new workbook, but they get pasted over anyway. I need some way to check in my script to not paste all that data over, only certain cells. For example: There is data in cells A- L, but I only need cells A-C and I-L cells pasted over only. I'm new to VBA. Below is what I have so far. NOTE: I have about 10 worksheets in the workbook and one of the files I need copied are one of the worksheets. The pasted data will be in a separate workbook.
Sub Results()
'to open the workbook that is saved in a folder on your system _
change the path according to the location you have in your _
system
Workbooks.Open "C:\Users\username\Desktop\Test.xlsx"
'copies cell from the book1 workbook and copy and paste _
it to the workbook myFile
Workbooks("Test.xlsx").Worksheets("data_to_copy").Range("A1:A1940").copy _
Workbooks("Book2").Worksheets("Sheet1").Range("A1:Q1940")
End Sub
I also have a function that actually opens windows explorer and selects a file, but not sure how to implement this in the above script and checks each cell to past over.
Sub Open_Explorer()
Dim Folder As String
Folder = ActiveCell(1, 2).Value
Shell "C:\Windows\explorer.exe /select," & Folder & "\" & ActiveCell(1, 1).Value & ".xclx", vbMaximizedFocus
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|