I have some code that attempts to combine a number of worksheets into 1. The idea is that each of the source worksheets is pasted into the target worksheet in a specified order. The first action to take on the target worksheet is to delete all of the existing rows. After doing this I use the usedrange property of the sheet to add each of the source worksheets to the target. I expect the usedrange to be very small after deleting all of the rows. E.g., it would be useful if the value of worksheet.usedrange.rows.count would be 0 or 1. Instead it has the value from before the deletion of the rows. Code snippet follows - see below. Printing wksXml.UsedRange.Rows.Count yields some number in excess of 4000, which is how big it was after the last failed test.
Is this the correct behavior? If so, I guess I can delete the target worksheet and recreate it. Seems like a really blunt instrument.
' PrepareXML
' Copy the XML generated From SDL Details:
' 1. Sensors
' 2. Turnouts
' 3. Lights
' 4. Signal Heads
' 5. Signal Masts
' 6. Blocks
Const strSheets As String = "Sensors,Turnouts,Lights,SignalHeads,SignalMasts,Blocks"
Dim boolDbg As Boolean
Dim iRow As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim wks As Worksheet
Dim wksXml As Worksheet
Dim wksA As Worksheet
Set wksA = ActiveSheet
Set wksXml = Sheets("SdlXml")
wksXml.Activate
Application.Goto reference:=wksXml.Range("$A$1"), scroll:=True
wksXml.Range(wksXml.Cells(1, 1), wksXml.Cells(wksXml.UsedRange.Rows.Count,
wksXml.UsedRange.Columns.Count)).Delete