T
Tim
Hello experts,
I'm having a problem doing something I thought was rather simple.
What I'm doing is copying a worksheet from another file which can have any
number of rows in it into the current workbook.
Once the worksheet is copied in, I want to name a range that will start on
A3:B3 and go to A?:B3.
So I need to determine the last row with data in it, and name that range
"Units".
The code I have below winds up naming the range above A3:B3... So A1:B3 is
what ends up being named "Units".
Please, any help would be great. Thanks.
Dim strLastCell As String
strLastCell = ActiveSheet.Range("A65536").End(xlUp).Row
ChDir "C:\TS_Reports"
Workbooks.Open Filename:="C:\TS_Reports\Export_CAT.xls"
Sheets("#CU# Units").Select
Sheets("#CU# Units").Copy Before:=Workbooks("ReportWriter.xlsx").Sheets(1)
Windows("Export_CAT.xls").Activate
ActiveWindow.Close
Windows("ReportWriter.xlsx").Activate
Sheets("#CU# Units").Select
Range("A3:B3").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="Units", RefersToR1C1:= _
"='#CU# Units'!R3C1:R" & strLastCell & "C2"
Range("A3").Select
I'm having a problem doing something I thought was rather simple.
What I'm doing is copying a worksheet from another file which can have any
number of rows in it into the current workbook.
Once the worksheet is copied in, I want to name a range that will start on
A3:B3 and go to A?:B3.
So I need to determine the last row with data in it, and name that range
"Units".
The code I have below winds up naming the range above A3:B3... So A1:B3 is
what ends up being named "Units".
Please, any help would be great. Thanks.
Dim strLastCell As String
strLastCell = ActiveSheet.Range("A65536").End(xlUp).Row
ChDir "C:\TS_Reports"
Workbooks.Open Filename:="C:\TS_Reports\Export_CAT.xls"
Sheets("#CU# Units").Select
Sheets("#CU# Units").Copy Before:=Workbooks("ReportWriter.xlsx").Sheets(1)
Windows("Export_CAT.xls").Activate
ActiveWindow.Close
Windows("ReportWriter.xlsx").Activate
Sheets("#CU# Units").Select
Range("A3:B3").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="Units", RefersToR1C1:= _
"='#CU# Units'!R3C1:R" & strLastCell & "C2"
Range("A3").Select