victoriaharry
asked on
VBA Excel - Selection.ClearContents not resetting last row
Hi,
I have an excel macro that clears the contents of the spreadsheet then imports some data from word tables into the spreadsheet. It works fine the first time but the next time it appears to have issues with the way I'm finding the last popualted row. It seems to remember the previous last row and starts popualting the rows were the last run ended. Any ideas on how to reset it would be appreciated
Some code snippets are below
'Clear cells
Cells.select
Selection.ClearContents
Find = 0
lastRow = 6
For i = 1 To TableCount
'Check that first column in the document has header Req Name
If Left$(WordApp.Activedocume nt.Tables( i).cell(1, 1).Range.Text, 8) = "Req Name" Then
WordApp.Activedocument.Tab les(i).Ran ge.Copy
Sheet1.Range("A" & lastRow).PasteSpecial xlPasteValues
Find = 1
lastRow = ActiveSheet.Cells.SpecialC ells(xlCel lTypeLastC ell).Row
End If
Next
I have an excel macro that clears the contents of the spreadsheet then imports some data from word tables into the spreadsheet. It works fine the first time but the next time it appears to have issues with the way I'm finding the last popualted row. It seems to remember the previous last row and starts popualting the rows were the last run ended. Any ideas on how to reset it would be appreciated
Some code snippets are below
'Clear cells
Cells.select
Selection.ClearContents
Find = 0
lastRow = 6
For i = 1 To TableCount
'Check that first column in the document has header Req Name
If Left$(WordApp.Activedocume
WordApp.Activedocument.Tab
Sheet1.Range("A" & lastRow).PasteSpecial xlPasteValues
Find = 1
lastRow = ActiveSheet.Cells.SpecialC
End If
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.