Need help to understand script

  • Thread starter Crowbar via OfficeKB.com
  • Start date
C

Crowbar via OfficeKB.com

Can someone please tell me which part of this script refers to the columns.
Also, why it won't complile at line 3

Dim res as Variant, res1 as Variant
dim qty as Long, pounds as Long
Dim i as Long, LastRow as Long
res = InputBox("Enter Minimum Items to Stay")
res1 = Inputbox("Enter Minimum £ to Stay")
if not(isnumeric(res) and isnumeric(res1)) then
msgbox "Invalid Values, quiting"
exit sub
end if
qty = clng(res)
pounds = clng(res1)

lastrow = cells(rows.count,1).End(xlup).row
for i = lastrow to 2 step -1
if cells(i,1) < qty and cells(i,2) < pounds then
rows(i).Delete
end if
Next
 
T

Tom Ogilvy

I copied it out of my posting and pasted it into a new module.

It compiled and Ran flawlessly - performing exactly as expected.

I have modified it to put in default values of 20 and 300 in the inputboxes,
so if you don't want to change you just hit OK or enter

I have also changed column references to Letters for ease of adjustment

If Cells(i, "A") < qty And Cells(i, "B") < pounds Then


Sub CC()
Dim res As Variant, res1 As Variant
Dim qty As Long, pounds As Long
Dim i As Long, LastRow As Long
res = InputBox("Enter Minimum Items to Stay", _
Default:=20)
res1 = InputBox("Enter Minimum £ to Stay", _
Default:=300)
If Not (IsNumeric(res) And IsNumeric(res1)) Then
MsgBox "Invalid Values, quiting"
Exit Sub
End If
qty = CLng(res)
pounds = CLng(res1)

LastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = LastRow To 2 Step -1
If Cells(i, "A") < qty And Cells(i, "B") < pounds Then
Rows(i).Delete
End If
Next

End Sub
 
L

Leith Ross

Hello Crowbar,

I ran your code on my machine using Office 2000 and Windows XP. I
compiled and ran fine. What system and version of Office are yo
using?

Sincerely,
Leith Ros
 

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

Similar Threads

TOM it did not work... 2
The last nail... 3
Please Help! 1
Run two macros for two different sheets 11
A little more effort... 4
To give paste special (value) in macros 1
Can any body help? 1
x=inputbox 2

Top