Count in the first free column

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

I've the following job.

https://www.dropbox.com/s/ek5nyx5lnfxclog/Develop.xlsm?dl=0

In the sheet "Beta" you can find the data source (column D).

In the sheet "Alpha", in the first free column, I've to count the quantity of recurrence.


Now, I've identified the first free column in Alpha with:

Code:
Sub Alphabet()


With Sheets("Alpha")

    For I = 1 To Columns.Count
        If Cells(4, I) = "" Then Exit For
    Next I

    freecolumn = I

End With


End Sub

Now, how can I create the results below in Alpha using vba?

B5 = 1
B6 = 7
B7 = 7
B8 = 3
B9 = 1
B10 = 19
 
Last edited:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
First, you don't need to loop to find the first free column. But wouldn't it always be column 2?
If there are going to be more columns of data, can you please show what you would want to do in that case?
 
Upvote 0
Assuming your results will always be in Column B:

Code:
Sub CountOccurrences()
Dim lastrow As Long
lastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("B5:B" & lastrow - 1).Formula = "=COUNTIF(Beta!D:D,A5)"
Range("B" & lastrow).Formula = "=SUM(B4:B" & lastrow - 1 & ")"
Range("B5:B" & lastrow).Value = Range("B5:B" & lastrow).Value
End Sub
 
Upvote 0
First, you don't need to loop to find the first free column. But wouldn't it always be column 2?
No: suppose in B4 a header (example "20/2/18" produced by the sub); the following day the datas will be written in column C (the first free column with reference to row 4) and so on.
 
Upvote 0
Assuming your results will always be in Column B:

Code:
Sub CountOccurrences()
Dim lastrow As Long
lastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("B5:B" & lastrow - 1).Formula = "=COUNTIF(Beta!D:D,A5)"
Range("B" & lastrow).Formula = "=SUM(B4:B" & lastrow - 1 & ")"
Range("B5:B" & lastrow).Value = Range("B5:B" & lastrow).Value
End Sub

As specified with the previous post, the sub always writes in the first free column (B, than C, than D, ...) so as to avoid datas overwriting.
 
Upvote 0
So, I understand, the totals would be overwritten the next day and then it would look something like this and then you want new totals??


Excel 2010
AB
4LABELS2/20/2018
5LONDONPARIS
6PARISATHENS
7ROME
8ATHENS
9MADRID
10TOTAL
Alpha
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top