12,822,050 members (42,588 online)
Rate this:
See more:
Hi,

I want to read a particular application from a excel (current) and count it the number of times it has appeared in the excel.
Then in my master excel i have defined these applications, i want to create a column with name as "Aug 20" and corresponding to the application in excel it should add the count in master excel.
If there are not applications found in current excel then in master excel i want to add the count value to corresponding application in master excel as 0.

Please let me know how this can be achieved. I am not getting the logic to do this.

Thanks!
Posted 29-Aug-12 9:13am
Updated 29-Aug-12 9:58am
v2
Kenneth Haugland 29-Aug-12 14:58pm

This is rather simple to achive, but what have you tried?
losmac 29-Aug-12 15:12pm

Do you want to compare the data stored in 2 Excel sheets?
Do you really need vba? Can't you use Lookup or CountIf function?

Rate this:

## Solution 1

As i wrote in comment, you need only `CountIf` worksheet function. But if you would like to do it with VBA code, OK, i'll show you an example. Below code is to use when both excel files (master and current) are opened.

Copy the code below and paste it into master file in new module :
```Dim srcwsh as Worsheet, dstwsh As Worksheet
Dim i as Integer, j As Integer, counter as Integer
Dim sAppName As String

Set dstWsh = ThisWorkbook.Worksheets(1)
Set srcWsh = Application.Workbooks("current.xls").Worksheets(1)
counter = 0
i = 2 'start from row no. 2 in srcwsh
j = 2 'start from row no. 2 in dstwsh
Do While srcwsh.Range("A" & i)<>""
sAppName = srcwsh.Range("A" & i)
Do While dstwsh.Range("A" & j)<>""
If dstwsh.Range("A" & j) = sAppname Then counter = counter + 1
Loop
srcwsh.Range("B" & i) = counter
counter = 0 'new application, so reset counter
Loop```

This is not optimal code, because it compares data row by row (cell by cell), but it shows "logic".
v2
Kenneth Haugland 29-Aug-12 15:46pm

Sheet.UsedRange is much faster than looping :)
losmac 29-Aug-12 15:47pm

... to count applications in both files?
How do you want to use it? If you know an answer, post it!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 290 Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ) 100 Bryian Tan 85 Dave Kreskowiak 65 ppolymorphe 62
 OriginalGriff 5,087 Graeme_Grant 3,834 Karthik Bangalore 3,536 ppolymorphe 2,584 Jochen Arndt 2,571

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 29 Aug 2012