Add Selected Items

S

Soniya

Hi all,


I have Rec_No in my column A and amount in Column B

something like

Rec_No Amount
1 50
2 25
4 35
8 200
10 100
11 15
12 20

I want the user to select From and To rec no and add only
items between those nmbers including start and end no.

If I use a UserForm with Two text boxes users can enter
start receipt and end receipt no. But How can I select
those items only and sum that selection and dispaly the
result in the user form?


TIA
soniya
 
T

Tom Ogilvy

Dim tot as Long, lngStart as Long
Dim lngEnd as Long, i as Long
tot = 0
lngStart = clng(textbox1.Text)
lngEnd = clng(Textbox2.Text)
for i = 2 to 8
if cells(i,1)>= lngStart and cells(i,1)<=lngEnd then _
tot = tot + cells(i,2).Vaue
end if
Next
Textbox3.Text = tot
 

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