Burrgogi
Well-known Member
- Joined
- Nov 3, 2005
- Messages
- 502
- Office Version
- 2010
- Platform
- Windows
I have a macro works roughly 70% of the time.
Occasionally it throws up an error on the very last line just before End With. Initially I had it written as .Formula, then I realized I needed .FormulaR1C1. I thought I fixed it for good but it still pops up with an error occasionally.
Column B is not part of the table. I beginning to suspect maybe that's why it's causing the error. I don't know why it works sometimes and not others.
VBA Code:
Dim Tbl1 As ListObject
Dim KeyWord As String
Set Tbl1 = ThisWorkbook.Worksheets("Sheet3").ListObjects("My_Table")
With Tbl1
'shift from an extra row if list has header
Dim iHeader As Long
If .Sort.Header = xlYes Then
iHeader = 1
Else
iHeader = 0
End If
'find the last row of the list
tLastRow = Tbl1.ListRows.Count + 1
'add the data a row after the end of the list
Tbl1.Range(tLastRow + iHeader, "A").Value = KeyWord
Tbl1.Range(tLastRow + iHeader, "B").FormulaR1C1 = "=VLOOKUP(RC1,'Complete Set'!R2C1:R2617C3,3,FALSE)"
End With
Occasionally it throws up an error on the very last line just before End With. Initially I had it written as .Formula, then I realized I needed .FormulaR1C1. I thought I fixed it for good but it still pops up with an error occasionally.
Column B is not part of the table. I beginning to suspect maybe that's why it's causing the error. I don't know why it works sometimes and not others.