Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Count transacton

0

hi ,

i just want to how to count no of transaction from invoice no column,

coloumn A contains invoice no ,coloumn B contains cusotmer ID

now i want to count each customer's no of transactions with us

Kindly explain 

Answer
Discuss

Answers

0

Ramzein

Not sure how many customers you have but the simplest way to count the transactions for a customer is using the worksheet function COUNTIF....

If each invoice counts as a tranaction (but some businesses may have several invoices per order) and you have invoice details in rows 2 to 30 (say) then put this in a cell: 

=COUNTIF(B2:B30,"=CustomerID")

and (once you change the bits in bold above, e.g. replacing CustomerID with a real value) that cell will count them.

Be careful not to introduce spaces before or after CustomerID in the equation (or transaction list) or the result will be wrong.

REVISION 1:  I've removed the wording about using the worksheet function COUNTIF in VBA, since for some odd reason I can't use any worksheet functions in VBA at present, not even SUM!

To illustrate the formulae above, I've attached a version of the file I sent in reply to your question last week. In this, I've added several invoices from the Invoice sheet but changed the CustomerID for a couple of the rows.

In this file please see the yellow cells B1:D1 in the "Invoice Inventory" sheet. Here:

B1 includes a customerID

C1 is the COUNTIF formula with the CustomerID "hard coded" in the formula:

=COUNTIF(B4:B30,"=smc001")

D1 refers to B1 instead (so you can change)

=COUNTIF(B4:B30,B1)
 

Both C1 and D1 correctly report 3 transactions for "smc001"

REVISION 2: see second attached file Count trans v0_a.xlsx (a version of what you just sent)where the formula in A1 of Invoice Invenrtory counts the transactions for a hard-coded customer.

REVISION 3: There's something odd about the file "Invoice macros.." from last week which disables WorksheetFunctions somehow but they DO work onother workbooks (phew!) so...

I've replaced the second file with a macro-enabled version Count trans v0_b.xlsm  which also has a macro in Sheet10 (Invoice Main (2)) which takes a CustomerID from the use and preport the count in a message box. Here's the simple code (in which you might need to chnage the bit in bold later on or autodetect the use in that column):

Sub CountTrans()

r = InputBox("Enter a CustomerID:", "Count transactions", "smc046")

MsgBox Application.WorksheetFunction.CountIf(Range("C3:C30"), r) & " transactions counted for " & r

End Sub
Discuss

Discussion

hi, John
I already tried the same before i post this but the formula returns zero
kindly view attached , i tried both ways

Thanks,

i dont see a option to upload the sample file
Ramzein (rep: 8) Nov 23, '20 at 1:17 am
Ramzein

I cannot see what you meant to attach (note that the discussion posts do not accept image/ screen grabs, only Excel files are allowed).

If you want to add a sample file, please Edit your question then pick Add Files (below the text box) then Submit.
John_Ru (rep: 6142) Nov 23, '20 at 4:42 am
hi John,

kindly view the file i uploaded

Thanks
Ramzein (rep: 8) Nov 23, '20 at 6:31 am
Ramzein

Please see Revision 1 to my Answer above. Not sure why VBA worksheet functions isn't working, not seen that before!
John_Ru (rep: 6142) Nov 23, '20 at 6:40 am
Now see Revision 2 and the file that put a formula in your second sheet.s
John_Ru (rep: 6142) Nov 23, '20 at 6:46 am
Ramzein,

Hopefully revision 3 to the Answer gives you all you need.
John_Ru (rep: 6142) Nov 23, '20 at 7:39 am
Hi  John,

The result is correct refering to coloumn B (customer id ) what im trying to ask is from coloumn A ( invoice# ) as i may enter customer id not only for new transaction 
even when the payment is being made by the same customer, so ther will no invoice no in that row.

i want to count only the invoices ( from coloumn A) , if i refer cloumn B it counts all
transaction of that customer ( payments & new invoices)

inv no    customer id     inv total  payment
1122      smc001           1000
              smc001                             500
              smc001                             500


As per above smc001 made 1 transaction but he paid partialy , so im not going to count the payments but the invoices

smc001 repeated thrice but new invoice transaction one

hope i have clearly stated pls correct me if im wrong 

Thanks
Ramzein (rep: 8) Nov 24, '20 at 2:17 am
Ramzein

I thought I had answered your Question (as stated originally) using VBA and a worksheet formula (on "Customer ID").

Now I do not know what you want or which file you are referring to in your message above - the file in the Question has "Invoice No" as column B (not A) and "Cus Code" in column C, unlike your points above. Also it does not have smc001 or the values you mention. Equally the older file I modified/ attached to my answer ("Invoice macros...") does not have those invoice/paid values.

Please make your requirements clear (the outcome you required on a sample file) in the Question (not this discussion).

Only then can anyone reply properly.
John_Ru (rep: 6142) Nov 24, '20 at 4:33 am
Ramzein

I see you just asked a question online. Please respond on this discussion too.
John_Ru (rep: 6142) Nov 26, '20 at 1:18 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login