PC Review


Reply
Thread Tools Rate Thread

Check if all values in a column is identical

 
 
Mr. Smith
Guest
Posts: n/a
 
      19th Oct 2007
Hi.
(VBA scripting in Excel 2003)

Case:
If all values in column A are identical, Then
No need to activate SUBTOTAL on the data.
Else
Activate SUBTOTALS.
End if

What would be a "slick" way of checking column A for changing values? The
smartes way I can think of is something like this

chkstr = Range("A2")
For i = 3 to LastRowOfData 'Data starts in row 2, row 1 contains heading
If Cells("A"&i) <> chkstr Then
GoTo: InsertSubtotals
Next i

'Not even sure if it would work.....

Kind regards
Mr. Smith






 
Reply With Quote
 
 
 
 
papou
Guest
Posts: n/a
 
      19th Oct 2007
Hello Mr. Smith
Here's a suggestion (dunno if its smarter!)
Amend with the relevant range reference:
'if identical values found exit the sub
If Evaluate("COUNTIF(A2:A76,A2)=COUNTA(A2:A76)") Then Exit Sub

HTH
Cordially
Pascal


"Mr. Smith" <(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...
> Hi.
> (VBA scripting in Excel 2003)
>
> Case:
> If all values in column A are identical, Then
> No need to activate SUBTOTAL on the data.
> Else
> Activate SUBTOTALS.
> End if
>
> What would be a "slick" way of checking column A for changing values? The
> smartes way I can think of is something like this
>
> chkstr = Range("A2")
> For i = 3 to LastRowOfData 'Data starts in row 2, row 1 contains heading
> If Cells("A"&i) <> chkstr Then
> GoTo: InsertSubtotals
> Next i
>
> 'Not even sure if it would work.....
>
> Kind regards
> Mr. Smith
>
>
>
>
>
>



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      19th Oct 2007
You could use this approach

If
ActiveSheet.Evaluate("SUMPRODUCT((A2:A20<>"""")/COUNTIF(A2:A20,A2:A20&""""))")
> 1 Then

MsgBox "yes"
Else
MsgBox "no"
End If


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Mr. Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi.
> (VBA scripting in Excel 2003)
>
> Case:
> If all values in column A are identical, Then
> No need to activate SUBTOTAL on the data.
> Else
> Activate SUBTOTALS.
> End if
>
> What would be a "slick" way of checking column A for changing values? The
> smartes way I can think of is something like this
>
> chkstr = Range("A2")
> For i = 3 to LastRowOfData 'Data starts in row 2, row 1 contains heading
> If Cells("A"&i) <> chkstr Then
> GoTo: InsertSubtotals
> Next i
>
> 'Not even sure if it would work.....
>
> Kind regards
> Mr. Smith
>
>
>
>
>
>



 
Reply With Quote
 
Mr. Smith
Guest
Posts: n/a
 
      19th Oct 2007
Nice twist Cordially!

Thanks!
Mr. Smith

"papou" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hello Mr. Smith
> Here's a suggestion (dunno if its smarter!)
> Amend with the relevant range reference:
> 'if identical values found exit the sub
> If Evaluate("COUNTIF(A2:A76,A2)=COUNTA(A2:A76)") Then Exit Sub
>
> HTH
> Cordially
> Pascal
>
>
> "Mr. Smith" <(E-Mail Removed)> a écrit dans le message de news:
> (E-Mail Removed)...
>> Hi.
>> (VBA scripting in Excel 2003)
>>
>> Case:
>> If all values in column A are identical, Then
>> No need to activate SUBTOTAL on the data.
>> Else
>> Activate SUBTOTALS.
>> End if
>>
>> What would be a "slick" way of checking column A for changing values? The
>> smartes way I can think of is something like this
>>
>> chkstr = Range("A2")
>> For i = 3 to LastRowOfData 'Data starts in row 2, row 1 contains heading
>> If Cells("A"&i) <> chkstr Then
>> GoTo: InsertSubtotals
>> Next i
>>
>> 'Not even sure if it would work.....
>>
>> Kind regards
>> Mr. Smith
>>
>>
>>
>>
>>
>>

>
>



 
Reply With Quote
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      19th Oct 2007
Just test if the MAX equals the MIN.
--
Gary''s Student - gsnu2007


"Mr. Smith" wrote:

> Hi.
> (VBA scripting in Excel 2003)
>
> Case:
> If all values in column A are identical, Then
> No need to activate SUBTOTAL on the data.
> Else
> Activate SUBTOTALS.
> End if
>
> What would be a "slick" way of checking column A for changing values? The
> smartes way I can think of is something like this
>
> chkstr = Range("A2")
> For i = 3 to LastRowOfData 'Data starts in row 2, row 1 contains heading
> If Cells("A"&i) <> chkstr Then
> GoTo: InsertSubtotals
> Next i
>
> 'Not even sure if it would work.....
>
> Kind regards
> Mr. Smith
>
>
>
>
>
>
>

 
Reply With Quote
 
Mr. Smith
Guest
Posts: n/a
 
      19th Oct 2007
Very elegant Gary's

Kind regards
Mr. Smith

"Gary''s Student" <(E-Mail Removed)> wrote in message
news:17B7A82C-34DF-433C-AF12-(E-Mail Removed)...
> Just test if the MAX equals the MIN.
> --
> Gary''s Student - gsnu2007
>
>
> "Mr. Smith" wrote:
>
>> Hi.
>> (VBA scripting in Excel 2003)
>>
>> Case:
>> If all values in column A are identical, Then
>> No need to activate SUBTOTAL on the data.
>> Else
>> Activate SUBTOTALS.
>> End if
>>
>> What would be a "slick" way of checking column A for changing values? The
>> smartes way I can think of is something like this
>>
>> chkstr = Range("A2")
>> For i = 3 to LastRowOfData 'Data starts in row 2, row 1 contains heading
>> If Cells("A"&i) <> chkstr Then
>> GoTo: InsertSubtotals
>> Next i
>>
>> 'Not even sure if it would work.....
>>
>> Kind regards
>> Mr. Smith
>>
>>
>>
>>
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check values in each column Martin Microsoft Excel Programming 4 22nd Nov 2009 07:08 AM
Merging files with nearly identical values in one column Allen Microsoft Excel Misc 3 4th Mar 2009 05:09 PM
Loop through column(s) to check values, perform action based on check ward376 Microsoft Excel Programming 4 6th Nov 2007 03:21 PM
form - check for identical values (password / email) =?Utf-8?B?WGF2aWVy?= Microsoft ASP .NET 0 21st Feb 2006 06:04 PM
Search identical values in a column haan0054 Microsoft Excel Worksheet Functions 1 28th Sep 2004 04:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:27 AM.