Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Count Uniques in Col H, Result in Blank Cell, For Each Next Loop

I am trying to figure out how to structure some code to be able ot count
unique numbers, all in Column H, for about 4000+ rows, and place the count of
the unique numbers in the first blanks space under each 'array' of numbers
(some unique and some dupes), in Column H.

The code may be similar to this...not exactly sure...
Dim lastrow as long
For each blank in Range("H2:H4000").Select

lastrow = .Cells(.Rows.Count, "H").End(xlUp).Row
..Cells(lastrow, "H").Activate
ActiveCell.FormulaR1C1 = "=count(1/FREQUENCY(r2c:r[-1]c)"

Next blank

I am assuming uniques can be counted with this function:
=COUNT(1/FREQUENCY(H2:H4000,H2:H4000))


Any thoughts on this?


Thanks so much,
Ryan---


--
RyGuy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,393
Default Count Uniques in Col H, Result in Blank Cell, For Each Next Loop

Why activate a cell? Would this not work
..Cells(lastrow, "H").FormulaR1C1 = "formula"

The FREQUENCY part of your formula does not look right - only one argument
I like to use this form
=SUMPRODUCT(--(D1:D4<""),1/COUNTIF(D1:D4,D1:D4&""))

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"ryguy7272" wrote in message
...
I am trying to figure out how to structure some code to be able ot count
unique numbers, all in Column H, for about 4000+ rows, and place the count
of
the unique numbers in the first blanks space under each 'array' of numbers
(some unique and some dupes), in Column H.

The code may be similar to this...not exactly sure...
Dim lastrow as long
For each blank in Range("H2:H4000").Select

lastrow = .Cells(.Rows.Count, "H").End(xlUp).Row
.Cells(lastrow, "H").Activate
ActiveCell.FormulaR1C1 = "=count(1/FREQUENCY(r2c:r[-1]c)"

Next blank

I am assuming uniques can be counted with this function:
=COUNT(1/FREQUENCY(H2:H4000,H2:H4000))


Any thoughts on this?


Thanks so much,
Ryan---


--
RyGuy



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Count Uniques in Col H, Result in Blank Cell, For Each Next Lo

Thanks for the tip Bernard, but it didn't seem to work for me. I must be
doing something wrong. I fiddled with it a bit, and came up with the code
below:
Sub CountUniques()

Dim sh As Worksheet, c As Range
lastrow = sh.Cells(Rows.Count, 8).End(xlUp).Row
For Each c In sh.Range("H2:H" & lastrow)
If c = "" Then
.Cells(lastrow, "H").Activate
ActiveCell.FormulaR1C1 = _

"=SUMPRODUCT((r2c:R[-1]C<"""")/(COUNTIF(r2c:R[-1]C,r2c:R[-1]C&"""")))"
Next
End Sub

To me, this looks like it should work, but it doesn't. It fails on this line:
..Cells(lastrow, "H").Activate
Error Message = Compile Error: Invalid or unqualified reference.


I'd appreciate any help with this.

Thanks,
Ryan---

--
RyGuy


"Bernard Liengme" wrote:

Why activate a cell? Would this not work
..Cells(lastrow, "H").FormulaR1C1 = "formula"

The FREQUENCY part of your formula does not look right - only one argument
I like to use this form
=SUMPRODUCT(--(D1:D4<""),1/COUNTIF(D1:D4,D1:D4&""))

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"ryguy7272" wrote in message
...
I am trying to figure out how to structure some code to be able ot count
unique numbers, all in Column H, for about 4000+ rows, and place the count
of
the unique numbers in the first blanks space under each 'array' of numbers
(some unique and some dupes), in Column H.

The code may be similar to this...not exactly sure...
Dim lastrow as long
For each blank in Range("H2:H4000").Select

lastrow = .Cells(.Rows.Count, "H").End(xlUp).Row
.Cells(lastrow, "H").Activate
ActiveCell.FormulaR1C1 = "=count(1/FREQUENCY(r2c:r[-1]c)"

Next blank

I am assuming uniques can be counted with this function:
=COUNT(1/FREQUENCY(H2:H4000,H2:H4000))


Any thoughts on this?


Thanks so much,
Ryan---


--
RyGuy




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,393
Default Count Uniques in Col H, Result in Blank Cell, For Each Next Lo

I am assuming that column H contains entries with a empty cells every so
often:
a,b,a,b, <blank, a,a,a, <blank
You want to count the number of unique items in each block by replacing the
blank with a formula.
I have assumed there are only single blanks, this lets me simplify the
SUMPRODUCT; you can change it if needed
The statement Cells(j, "H").Interior.Color = 65535 was used to help me
debug the code; remove it if you wish


Sub CountUniques()
Dim sh As Worksheet, c As Range
'lastrow = sh.Cells(Rows.Count, 8).End(xlUp).Row
lastrow = Cells(Cells.Rows.Count, "H").End(xlUp).Row + 1
toprow = 1
For j = 1 To lastrow
If Cells(j, "H") = "" Then
mycount = j - toprow
myrange = "R[-" & mycount & "]C:R[-1]C"
myeqn = "=sumproduct(1/countif(" & myrange & "," & myrange & "))"
Cells(j, "H") = myeqn
Cells(j, "H").Interior.Color = 65535
toprow = j + 1
End If
Next
End Sub

best wsihes -- let me know if this works for you
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"ryguy7272" wrote in message
...
Thanks for the tip Bernard, but it didn't seem to work for me. I must be
doing something wrong. I fiddled with it a bit, and came up with the code
below:
Sub CountUniques()

Dim sh As Worksheet, c As Range
lastrow = sh.Cells(Rows.Count, 8).End(xlUp).Row
For Each c In sh.Range("H2:H" & lastrow)
If c = "" Then
.Cells(lastrow, "H").Activate
ActiveCell.FormulaR1C1 = _

"=SUMPRODUCT((r2c:R[-1]C<"""")/(COUNTIF(r2c:R[-1]C,r2c:R[-1]C&"""")))"
Next
End Sub

To me, this looks like it should work, but it doesn't. It fails on this
line:
.Cells(lastrow, "H").Activate
Error Message = Compile Error: Invalid or unqualified reference.


I'd appreciate any help with this.

Thanks,
Ryan---

--
RyGuy


"Bernard Liengme" wrote:

Why activate a cell? Would this not work
..Cells(lastrow, "H").FormulaR1C1 = "formula"

The FREQUENCY part of your formula does not look right - only one
argument
I like to use this form
=SUMPRODUCT(--(D1:D4<""),1/COUNTIF(D1:D4,D1:D4&""))

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"ryguy7272" wrote in message
...
I am trying to figure out how to structure some code to be able ot count
unique numbers, all in Column H, for about 4000+ rows, and place the
count
of
the unique numbers in the first blanks space under each 'array' of
numbers
(some unique and some dupes), in Column H.

The code may be similar to this...not exactly sure...
Dim lastrow as long
For each blank in Range("H2:H4000").Select

lastrow = .Cells(.Rows.Count, "H").End(xlUp).Row
.Cells(lastrow, "H").Activate
ActiveCell.FormulaR1C1 = "=count(1/FREQUENCY(r2c:r[-1]c)"

Next blank

I am assuming uniques can be counted with this function:
=COUNT(1/FREQUENCY(H2:H4000,H2:H4000))


Any thoughts on this?


Thanks so much,
Ryan---


--
RyGuy






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Count Uniques in Col H, Result in Blank Cell, For Each Next Lo

I am in awe!!! I have to study the logic and learn from this...
Thanks so much!!
Ryan---


--
RyGuy


"Bernard Liengme" wrote:

I am assuming that column H contains entries with a empty cells every so
often:
a,b,a,b, <blank, a,a,a, <blank
You want to count the number of unique items in each block by replacing the
blank with a formula.
I have assumed there are only single blanks, this lets me simplify the
SUMPRODUCT; you can change it if needed
The statement Cells(j, "H").Interior.Color = 65535 was used to help me
debug the code; remove it if you wish


Sub CountUniques()
Dim sh As Worksheet, c As Range
'lastrow = sh.Cells(Rows.Count, 8).End(xlUp).Row
lastrow = Cells(Cells.Rows.Count, "H").End(xlUp).Row + 1
toprow = 1
For j = 1 To lastrow
If Cells(j, "H") = "" Then
mycount = j - toprow
myrange = "R[-" & mycount & "]C:R[-1]C"
myeqn = "=sumproduct(1/countif(" & myrange & "," & myrange & "))"
Cells(j, "H") = myeqn
Cells(j, "H").Interior.Color = 65535
toprow = j + 1
End If
Next
End Sub

best wsihes -- let me know if this works for you
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"ryguy7272" wrote in message
...
Thanks for the tip Bernard, but it didn't seem to work for me. I must be
doing something wrong. I fiddled with it a bit, and came up with the code
below:
Sub CountUniques()

Dim sh As Worksheet, c As Range
lastrow = sh.Cells(Rows.Count, 8).End(xlUp).Row
For Each c In sh.Range("H2:H" & lastrow)
If c = "" Then
.Cells(lastrow, "H").Activate
ActiveCell.FormulaR1C1 = _

"=SUMPRODUCT((r2c:R[-1]C<"""")/(COUNTIF(r2c:R[-1]C,r2c:R[-1]C&"""")))"
Next
End Sub

To me, this looks like it should work, but it doesn't. It fails on this
line:
.Cells(lastrow, "H").Activate
Error Message = Compile Error: Invalid or unqualified reference.


I'd appreciate any help with this.

Thanks,
Ryan---

--
RyGuy


"Bernard Liengme" wrote:

Why activate a cell? Would this not work
..Cells(lastrow, "H").FormulaR1C1 = "formula"

The FREQUENCY part of your formula does not look right - only one
argument
I like to use this form
=SUMPRODUCT(--(D1:D4<""),1/COUNTIF(D1:D4,D1:D4&""))

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"ryguy7272" wrote in message
...
I am trying to figure out how to structure some code to be able ot count
unique numbers, all in Column H, for about 4000+ rows, and place the
count
of
the unique numbers in the first blanks space under each 'array' of
numbers
(some unique and some dupes), in Column H.

The code may be similar to this...not exactly sure...
Dim lastrow as long
For each blank in Range("H2:H4000").Select

lastrow = .Cells(.Rows.Count, "H").End(xlUp).Row
.Cells(lastrow, "H").Activate
ActiveCell.FormulaR1C1 = "=count(1/FREQUENCY(r2c:r[-1]c)"

Next blank

I am assuming uniques can be counted with this function:
=COUNT(1/FREQUENCY(H2:H4000,H2:H4000))


Any thoughts on this?


Thanks so much,
Ryan---


--
RyGuy






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
count uniques anomaly T. Valko Excel Worksheet Functions 4 July 6th 08 05:54 AM
count uniques in same column, post in blank cell, repeat until end ofspreadsheet S Himmelrich Excel Programming 2 January 15th 08 07:31 PM
Count Uniques in Column, put result in next blank cell andcontinue until last row merjet Excel Programming 2 January 15th 08 05:31 PM
Count Uniques in Column, put result in next blank cell and continu ryguy7272 Excel Programming 1 January 15th 08 05:29 PM
Count Uniques within a list based on value of cell... MeatLightning Excel Discussion (Misc queries) 3 March 20th 06 05:21 PM


All times are GMT +1. The time now is 10:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"