I'm fairly new to VBA coding and I am trying to use Dim rather than select and activate as I've been told the latter slows down your code.
I require my code to open an external workbook (Workbook2) and copy some data and paste it into the existing workbook (Workbook1).
Currently, I'm trying to define the name of a worksheet in Workbook2 by using a named range in Workbook1. That way, if the worksheet name changes in Workbook2 one can dynamically do it from a cell in Workbook1. However, I get a "subscript-out-of-range-error" on the final line.
Any assistance would be much appreciated.
Sub PropertyMark()
'Define Name Ranges as helpers.
Dim NamePropWS1 As String
NamePropWS1 = Range("NamePropWS1").Value
'DefineWorkbooks and Worksheets.
Dim ConsWB As Workbook
Dim ConsWS As Worksheet
Dim PropWB As Workbook
Dim PropWS1 As Worksheet
Set ConsWB = ThisWorkbook
'Open up Property Portfolio and begin running Code
Workbooks.Open Filename:=Range("PropertyFileAddress").Value
Set PropWB = ThisWorkbook
Set PropWS1 = PropWB.Worksheets(NamePropWS1)
End Sub