I'm new to VBA and am trying to write a macro to move data from an exported file to an excel template. The code below works, however I have to add many more ranges of data and am worried it will be hefty to run.
Sub MoveData() Dim fileName As String Sheets("Cover").Select ' range("B5").Select fileName = Selection.Value Dim path As String path = "C:\Users\(name)\Documents\(folder)\" & fileName & ".csv" Dim currentWB As Workbook Set currentWB = ThisWorkbook Dim openWB As Workbook Set openWB = Workbooks.Open(path) Dim openWs As Worksheet Set openWs = openWB.Sheets(fileName) openWs.range("C2:C51").Copy openWB.Close (False) currentWB.Worksheets("Bms").Activate range("C7:C56").Select ActiveSheet.Paste End Sub
I took the base code from here(the closed section) and modified it to fit my needs. The file I am extracting data from will change, but will always be in the same folder, which is why I set up the path as such. I am moving the data from C2 and downwards to C7-down on the template. C56 is currently the last used cell on the template, however that is subject to change so I would prefer to get rid of the lower bound.
If there is a better way to write this, I would love some input. Since I'm still new at this, if you could explain your code as well, that would be very beneficial.