0
votes

Hi I am struggling to get my code to run and would really appreciate some help as it is my first time working with Visual Basics.

Error: Run-time error '1004': Method 'Range' of object '_Global' failed

Part of code highlighted as error:

Dim i As Long, lastrow As Long
lastrow = Cells.Find(What:="*", _
After:=Range("Ai"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row

Yellow arrow next to this line: MatchCase:=False).Row

Solution: Changed

After:=Range("Ai"), _

to

After:=Range("A" & Rows.Count), _
   
1

1 Answers

1
votes

Try changing

After:=Range("Ai"), _

with

After:=Range("A" & i), _

Anyhow, a simple way of obtaining the last row of A:A column would be:

LastRow = Range("A" & rows.count).End(xlup).row