Delete row on another sheet same workbook problem

L

Les Stout

Hi all, i am using the code below and it is not working as i want it to,
could somebody please help me ??
When i want to run this i am in the sheet Recon and it counts the rows
in recon ??

Sub DeleteInvoice()
'
Dim i As Long, iLastRow As Long
Dim myInv As String
myInv = InputBox("PLease enter the number of the invoice to
delete...", "DELETE INVOICE", "024908")
With Sheets("Invoices")
iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 1 Step -1
If Cells(i, "A").Value = myInv Then
Rows(i).Delete
End If
Next i
End With
End Sub


Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
 
N

Nick Hodge

Les

What is 'not as expected'. The structure of the code is a little wierd in
that your with...end with block refers to Sheets("Invoices"), but it does
nothing on that sheet if you are running this with another sheet active
(Recon??) as the Cells(....) references with all refer to recon. Perhaps
you meant to prefix all those references with a period (.) so it refers to
the Invoices sheet???

Sub DeleteInvoice()
'
Dim i As Long, iLastRow As Long
Dim myInv As String
myInv = InputBox("PLease enter the number of the invoice to
delete...", "DELETE INVOICE", "024908")
With Sheets("Invoices")
iLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 1 Step -1
If .Cells(i, "A").Value = myInv Then
.Rows(i).Delete
End If
Next i
End With
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
web: www.nickhodge.co.uk
blog: www.nickhodge.co.uk/blog/

FREE UK OFFICE USER GROUP MEETING, MS READING, 27th APRIL 2007
www.officeusergroup.co.uk
 
S

Susan

what's your specific error & where?
from what i can see, you might need to change this:

myInv = InputBox("PLease enter the number of the invoice to
delete...", "DELETE INVOICE", "024908").value <-----

but i might be wrong because i haven't worked with input boxes.

so you're counting the rows in RECON but you're deleting in INVOICES?
where's the variable being passed from RECON?
:)
susan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top