Hi all! I am fairly new to VBA, and I am having trouble making an automated macro to copy data from a separate file.
I have posted the current code below, but I should explain what is happening. The workbook that the macro is in is called Scorecard, and this is where the data needs to get pasted. In the 'Scorecard' workbook, I have a cell containing the link to the file that data needs to be copied from, and that link is called 'Data_wkbk'.
Then I open the file linked in the 'Data_wkbk' cell as read only.
The range that I am copying is dynamic. The range is ultimately the variable 'FRange', and I know that the range is correct because I used a MsgBox to show that the range is B2:BW51, which is what I expected. The last 2 lines of the code is where it errors out (Run-time error '9': Subscript out of range). Can anybody help me understand why this isn't copying and pasting the data?
I have posted the current code below, but I should explain what is happening. The workbook that the macro is in is called Scorecard, and this is where the data needs to get pasted. In the 'Scorecard' workbook, I have a cell containing the link to the file that data needs to be copied from, and that link is called 'Data_wkbk'.
Then I open the file linked in the 'Data_wkbk' cell as read only.
The range that I am copying is dynamic. The range is ultimately the variable 'FRange', and I know that the range is correct because I used a MsgBox to show that the range is B2:BW51, which is what I expected. The last 2 lines of the code is where it errors out (Run-time error '9': Subscript out of range). Can anybody help me understand why this isn't copying and pasting the data?
VBA Code:
Sub RetreiveData()
Dim scorecard As Workbook
Set scorecard = ThisWorkbook
Dim data_wkbk As String
data_wkbk = Worksheets("Input").Range("data_wkbk").Value
Dim src As Workbook
Set src = Workbooks.Open(data_wkbk, True, True)
Dim SC_Input As String
SC_Input = src.Worksheets("Input").Range("SC_Input").Value
Dim FRange As String
FRange = "B2:BW" & SC_Input
src.Worksheets("Build SLIME Data").Range("FRange").Copy
scorecard.Worksheets("SLIME Set Data").Range("A6").PasteSpecial Paste:=xlPasteValues
End Sub