K
KenY
Hi
I have previous experience of consolidating several worksheets into a single
worksheet and my method has worked well.
Typically, the method is:
'select a cell in the table, take a row count and copy it
Cells(5, 5).Select
Selection.CurrentRegion.Select
add_rows_cntr = Selection.CurrentRegion.Rows.Count
Selection.Copy
' paste the data values back into the consolidation
' check that there is space in the consolidation worksheet
If curr_rows_cntr + add_rows_cntr > 65536 Then MsgBox "Spreadsheet
Overflow": GoTo abort_consolid_loop
Windows("CAT_Consolidation.xls").Activate
Sheets("All_CAT_Data").Activate
' select the first empty row in the consolidation worksheet and paste the
data
Cells(curr_rows_cntr + 1, 4).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
So far, so good. Except I now have a scenario where the row count of my
current region is returned=1, but the copied area is 31 rows long. When I
check things manually in the source worksheet, using the cntl* command to
identify the current region (having selected the same cell as in macro), the
full 31 row area is selected.
The cause of the difference seems to be where the blank cells lie within my
'CurrentRegion', but it bothers me that the Excel behaviour is not the same
for the statements
' add_rows_cntr = Selection.CurrentRegion.Rows.Count' and
' Selection.CurrentRegion.Select
Selection.Copy'
Has anyone come across this and found a solution?
Data area format that throws the problem (hope this shows up ok in the post):
Value1 <blank> <blank> <blank>
<blank> <blank> <blank> Head1
<blank> Head2 Head3 Head4
head5 Head6 Head7 Head8
Value2 <blank> Value3 Value4
Value5 Value6 Value7 <blank>
If I make sure that the first column is continuous, when I select head5 as
my active cell for and ask for the CurrentRegion, I get the result I want.
As I said, I am more concerned that I have found an inconsistent behaviour
(Excel 2003) rather than wanting to know how I can fix my table.
I have previous experience of consolidating several worksheets into a single
worksheet and my method has worked well.
Typically, the method is:
'select a cell in the table, take a row count and copy it
Cells(5, 5).Select
Selection.CurrentRegion.Select
add_rows_cntr = Selection.CurrentRegion.Rows.Count
Selection.Copy
' paste the data values back into the consolidation
' check that there is space in the consolidation worksheet
If curr_rows_cntr + add_rows_cntr > 65536 Then MsgBox "Spreadsheet
Overflow": GoTo abort_consolid_loop
Windows("CAT_Consolidation.xls").Activate
Sheets("All_CAT_Data").Activate
' select the first empty row in the consolidation worksheet and paste the
data
Cells(curr_rows_cntr + 1, 4).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
So far, so good. Except I now have a scenario where the row count of my
current region is returned=1, but the copied area is 31 rows long. When I
check things manually in the source worksheet, using the cntl* command to
identify the current region (having selected the same cell as in macro), the
full 31 row area is selected.
The cause of the difference seems to be where the blank cells lie within my
'CurrentRegion', but it bothers me that the Excel behaviour is not the same
for the statements
' add_rows_cntr = Selection.CurrentRegion.Rows.Count' and
' Selection.CurrentRegion.Select
Selection.Copy'
Has anyone come across this and found a solution?
Data area format that throws the problem (hope this shows up ok in the post):
Value1 <blank> <blank> <blank>
<blank> <blank> <blank> Head1
<blank> Head2 Head3 Head4
head5 Head6 Head7 Head8
Value2 <blank> Value3 Value4
Value5 Value6 Value7 <blank>
If I make sure that the first column is continuous, when I select head5 as
my active cell for and ask for the CurrentRegion, I get the result I want.
As I said, I am more concerned that I have found an inconsistent behaviour
(Excel 2003) rather than wanting to know how I can fix my table.