I am trying to copy and paste data to the last row and getting an error message at this code. Everything is working fine until I get to this section.
The full code for this loop is below:
I have attached the spreadsheet with the code. is it my LastRow argument? Is it positioned appropriately in the loop. I am at a lost here
Thanks for your help.
Code:
Set DestCell = DestCell.Offset(LastRow - 8)
The full code for this loop is below:
Code:
'activate template
wkbkTemp.Activate
On Error Resume Next
Set TargetSh = Worksheets("Competitor")
On Error GoTo 0
Sheets("Competitor").Activate
Set DestCell = TargetSh.Range("COMPETITORS_START_CELL")
Set DestCell = DestCell.Offset(1, 0)
TargetSh.Activate
Rows("2:" & Rows.Count).ClearContents
'activate generator
wkbkGen.Activate
For Each MyCell In MyRange
If MyCell.Value = "" Then Exit For ' this exits when you have a blank cell
Worksheets("Disch by Sender and Receiver").Activate
'filter the sheet
Range("a5").Select
ActiveSheet.ShowAllData
If ActiveSheet.AutoFilterMode = False Then
Selection.AutoFilter
End If
'select the range and autofilter based on hospital name
ActiveSheet.Range("DISCH_BY_SENDER_RECEIVER_TBL").AutoFilter Field:=hospitalNameIndex, Criteria1:=MyCell
ActiveSheet.Range("DISCH_BY_SENDER_RECEIVER_TBL").AutoFilter Field:=16, Criteria1:=Array( _
"1", "2", "3"), Operator:=xlFilterValues
ActiveCell.CurrentRegion.Select
Set tbl = ActiveCell.CurrentRegion
tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1, tbl.Columns.Count).Select
Selection.Copy
'activate template
wkbkTemp.Activate
TargetSh.Activate
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
TargetSh.Range(DestCell.Address).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Set DestCell = DestCell.Offset(LastRow - 8)
Next MyCell
I have attached the spreadsheet with the code. is it my LastRow argument? Is it positioned appropriately in the loop. I am at a lost here
Thanks for your help.