Click here to Skip to main content
11,577,443 members (35,232 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: GimmeCode VBA
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 8:13am
Edited 29-Aug-12 8:58am
v2
Comments
Kenneth Haugland at 29-Aug-12 14:58pm
   
This is rather simple to achive, but what have you tried?
losmac at 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?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

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".
  Permalink  
v2
Comments
Kenneth Haugland at 29-Aug-12 15:46pm
   
Sheet.UsedRange is much faster than looping :)
losmac at 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)

  Print Answers RSS
0 DamithSL 155
1 Afzaal Ahmad Zeeshan 125
2 OriginalGriff 115
3 Richard MacCutchan 100
4 Abhinav S 90
0 OriginalGriff 820
1 Sergey Alexandrovich Kryukov 676
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 375


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 29 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100