Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Need code to compare cell values in a column

I am looking for some code that will allow me to check the cell values in a
column, if all the values in the column are the same I want to hide the
column, if any single value in the column is dissimilar I want the column to
stay visible. The row count for the columns is not static and can change
from sheet to sheet. Thanks for any assistance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need code to compare cell values in a column


Hi

try the code

Code:
--------------------

Sub test()
Dim myR As Range, myRange As Range, myCol As Integer, x
On Error GoTo Last
Set myR = Application.InputBox("select column haeding that you want to test", Type:=8)
Application.ScreenUpdating = False
With myR
myCol = .Column
Set myRange = Range(myR, Cells(65536, myCol).End(xlUp))
End With
On Error Resume Next
myRange.AdvancedFilter xlFilterInPlace, unique:=True
x = myRange.SpecialCells(xlCellTypeVisible).Count
If x <= 2 Then
ActiveSheet.ShowAllData
myRange.EntireColumn.Hidden = True
Else
ActiveSheet.ShowAllData
myRange.EntireColumn.Hidden = False
End If
Last:
Application.ScreenUpdating = True
End Sub

--------------------


--
jindon
------------------------------------------------------------------------
jindon's Profile: http://www.excelforum.com/member.php...o&userid=13135
View this thread: http://www.excelforum.com/showthread...hreadid=378003

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need code to compare cell values in a column


Another method:

sub test()
Set rng = Range("H4")
Set myRng = Range(rng, rng.End(xlDown))

If WorksheetFunction.CountIf(myRng, rng.Value) = myRng.Rows.Count
Then
rng.EntireColumn.Hidden = True
Else
rng.EntireColumn.Hidden = False
End If
end sub

Replace the "H4" with your first cell in the range.

Mangesh


--
mangesh_yadav
------------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...o&userid=10470
View this thread: http://www.excelforum.com/showthread...hreadid=378003

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
Look up values in one column and compare with another [email protected][_2_] New Users to Excel 2 November 13th 07 05:47 PM
How do I compare string values in one column to another column? Nick N. Excel Worksheet Functions 1 April 29th 06 02:56 AM
Code to compare cell values from different worksheets Ed P[_2_] Excel Programming 1 February 18th 05 03:26 PM
SOS VBA Code Emergency: need to copy tell to empty cell direct below where values in adjacent cells in different column are equal to each other. Steven Rosenberg Excel Programming 4 August 5th 03 05:05 AM


All times are GMT +1. The time now is 01:27 PM.

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

About Us

"It's about Microsoft Excel"