I'm running into a problem trying to select/copy certain ranges within my worksheet. I've narrowed it down as best as I can.
This works fine:
dataSheet.Cells(dRow, dataSheet.Range("IO_MODULES").Column).Select
This does not:
dataSheet.Range(Cells(dRow, dataSheet.Range("IO_MODULES").Column), Cells(dRow, dataSheet.Range("IO_MODULES").Column)).Select
This is what I'm trying to do:
dataSheet.Range(Cells(dRow, dataSheet.Range("IO_MODULES").Column), Cells(dRow, dataSheet.Range("MODULE_END").Column)).Copy Destination:= _
dataSheet.Range(Cells(dataSheet.Range("MODULE_1").Row + i - 1, dataSheet.Range("D_COUNT").Column + 1), Cells(dataSheet.Range("MODULE_1").Row + i - 1, dataSheet.Range("DATA_COL_END").Column))
I seem to be misunderstanding the relationship between Worksheet.Cells and Worksheet.Range. What I need to do is be able to select a range of cells based on the row and column numbers of cells that I've named.
.Select
-- here's a nice write-up about that: stackoverflow.com/questions/10714251/… – Dan WagnerCells
is an unqualified range object, so it always is implicitly defined asActiveSheet.Cells
. Therefore, you get an error withdataSheet.Range(Cells(...
unlessdataSheet
is theActiveSheet
. – David Zemens