Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Checking Cell Contents

Can someone advise how to do this; so far have been unsuccessful, but I think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these 5)
that have something in them (it would be text), I want to check to ensure
that the content is all the same, ignoring those that are blank. Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1 have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Checking Cell Contents

Are the blank cells empty or are the values produced produced by formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but I

think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these 5)
that have something in them (it would be text), I want to check to ensure
that the content is all the same, ignoring those that are blank. Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1

have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Checking Cell Contents

Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced produced by formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but I

think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these 5)
that have something in them (it would be text), I want to check to ensure
that the content is all the same, ignoring those that are blank. Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1

have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Checking Cell Contents

So I will assume the filled cells are constants (and not formulas

Sub CheckCells()
Dim rng as Range, rng1 as Range, cell as Range
Dim sStr as String
set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
set rng1 = rng.specialcells(xlconstants,xltextvalues)
On Error goto 0
if rng1 is nothing then
msgbox "All cells blank or contain other than text constants"
else
sStr = rng1(1)
for each cell in rng1
if cell.Value < sStr then
msgbox "Not all the same
exit sub
End if
Next
msgbox rng1.count & " cells all contain " & sStr
End if
end Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced produced by

formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but

I
think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these

5)
that have something in them (it would be text), I want to check to

ensure
that the content is all the same, ignoring those that are blank.

Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1

have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Checking Cell Contents

Thanks, Tom. I cannot get this to work. Regardless of what I put into the
cells, it only returns the msgbox "All cells blank or contain other than text
constants". Any advice?

"Tom Ogilvy" wrote:

So I will assume the filled cells are constants (and not formulas

Sub CheckCells()
Dim rng as Range, rng1 as Range, cell as Range
Dim sStr as String
set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
set rng1 = rng.specialcells(xlconstants,xltextvalues)
On Error goto 0
if rng1 is nothing then
msgbox "All cells blank or contain other than text constants"
else
sStr = rng1(1)
for each cell in rng1
if cell.Value < sStr then
msgbox "Not all the same
exit sub
End if
Next
msgbox rng1.count & " cells all contain " & sStr
End if
end Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced produced by

formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but

I
think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these

5)
that have something in them (it would be text), I want to check to

ensure
that the content is all the same, ignoring those that are blank.

Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1
have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Checking Cell Contents

What did you type in the cells?

Tom's code is looking for constants (not formulas) and text (not numbers).

Paige wrote:

Thanks, Tom. I cannot get this to work. Regardless of what I put into the
cells, it only returns the msgbox "All cells blank or contain other than text
constants". Any advice?

"Tom Ogilvy" wrote:

So I will assume the filled cells are constants (and not formulas

Sub CheckCells()
Dim rng as Range, rng1 as Range, cell as Range
Dim sStr as String
set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
set rng1 = rng.specialcells(xlconstants,xltextvalues)
On Error goto 0
if rng1 is nothing then
msgbox "All cells blank or contain other than text constants"
else
sStr = rng1(1)
for each cell in rng1
if cell.Value < sStr then
msgbox "Not all the same
exit sub
End if
Next
msgbox rng1.count & " cells all contain " & sStr
End if
end Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced produced by

formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but

I
think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these

5)
that have something in them (it would be text), I want to check to

ensure
that the content is all the same, ignoring those that are blank.

Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1
have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc







--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Checking Cell Contents

And is the activesheet the correct one?

Paige wrote:

Thanks, Tom. I cannot get this to work. Regardless of what I put into the
cells, it only returns the msgbox "All cells blank or contain other than text
constants". Any advice?

"Tom Ogilvy" wrote:

So I will assume the filled cells are constants (and not formulas

Sub CheckCells()
Dim rng as Range, rng1 as Range, cell as Range
Dim sStr as String
set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
set rng1 = rng.specialcells(xlconstants,xltextvalues)
On Error goto 0
if rng1 is nothing then
msgbox "All cells blank or contain other than text constants"
else
sStr = rng1(1)
for each cell in rng1
if cell.Value < sStr then
msgbox "Not all the same
exit sub
End if
Next
msgbox rng1.count & " cells all contain " & sStr
End if
end Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced produced by

formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but

I
think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these

5)
that have something in them (it would be text), I want to check to

ensure
that the content is all the same, ignoring those that are blank.

Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1
have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc







--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Checking Cell Contents

The active sheet is correct. I'm entering 'weekly', or 'monthly' or
'quarterly' in the cells, or nothing at all. So for those that have an
entry, they must match; if they do not match, I'm putting in a msgbox that
will pop up.

"Dave Peterson" wrote:

And is the activesheet the correct one?

Paige wrote:

Thanks, Tom. I cannot get this to work. Regardless of what I put into the
cells, it only returns the msgbox "All cells blank or contain other than text
constants". Any advice?

"Tom Ogilvy" wrote:

So I will assume the filled cells are constants (and not formulas

Sub CheckCells()
Dim rng as Range, rng1 as Range, cell as Range
Dim sStr as String
set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
set rng1 = rng.specialcells(xlconstants,xltextvalues)
On Error goto 0
if rng1 is nothing then
msgbox "All cells blank or contain other than text constants"
else
sStr = rng1(1)
for each cell in rng1
if cell.Value < sStr then
msgbox "Not all the same
exit sub
End if
Next
msgbox rng1.count & " cells all contain " & sStr
End if
end Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced produced by
formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but
I
think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these
5)
that have something in them (it would be text), I want to check to
ensure
that the content is all the same, ignoring those that are blank.
Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1
have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc







--

Dave Peterson

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Checking Cell Contents

This may not be too slick but it worked

Dim i As Long
Dim j As Long
Dim Cell As Range
Dim nCell As Long
Dim CellRef() As String

On Error Resume Next
Cells.SpecialCells(xlCellTypeConstants, xlTextValues).Select
If Selection.Count 1 Then
ReDim CellRef(Selection.Count)
For Each Cell In Selection
nCell = nCell + 1
CellRef(nCell) = Cell.Address(False, False)
Next Cell
For i = 1 To nCell - 1
For j = i + 1 To nCell
If Range(CellRef(i)).Value < Range(CellRef(j)).Value Then
MsgBox "Contents don't match in these cells: " & CellRef(i) & " " &
CellRef(j)
End If
Next j
Next i
End If


"Paige" wrote:

Thanks, Tom. I cannot get this to work. Regardless of what I put into the
cells, it only returns the msgbox "All cells blank or contain other than text
constants". Any advice?

"Tom Ogilvy" wrote:

So I will assume the filled cells are constants (and not formulas

Sub CheckCells()
Dim rng as Range, rng1 as Range, cell as Range
Dim sStr as String
set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
set rng1 = rng.specialcells(xlconstants,xltextvalues)
On Error goto 0
if rng1 is nothing then
msgbox "All cells blank or contain other than text constants"
else
sStr = rng1(1)
for each cell in rng1
if cell.Value < sStr then
msgbox "Not all the same
exit sub
End if
Next
msgbox rng1.count & " cells all contain " & sStr
End if
end Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced produced by

formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but

I
think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these

5)
that have something in them (it would be text), I want to check to

ensure
that the content is all the same, ignoring those that are blank.

Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1
have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc






  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Checking Cell Contents

Did you change this line:
set rng = Range("A1,B9,F2,A10,M3")
to the cell addresses that you wanted?

Paige wrote:

The active sheet is correct. I'm entering 'weekly', or 'monthly' or
'quarterly' in the cells, or nothing at all. So for those that have an
entry, they must match; if they do not match, I'm putting in a msgbox that
will pop up.

"Dave Peterson" wrote:

And is the activesheet the correct one?

Paige wrote:

Thanks, Tom. I cannot get this to work. Regardless of what I put into the
cells, it only returns the msgbox "All cells blank or contain other than text
constants". Any advice?

"Tom Ogilvy" wrote:

So I will assume the filled cells are constants (and not formulas

Sub CheckCells()
Dim rng as Range, rng1 as Range, cell as Range
Dim sStr as String
set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
set rng1 = rng.specialcells(xlconstants,xltextvalues)
On Error goto 0
if rng1 is nothing then
msgbox "All cells blank or contain other than text constants"
else
sStr = rng1(1)
for each cell in rng1
if cell.Value < sStr then
msgbox "Not all the same
exit sub
End if
Next
msgbox rng1.count & " cells all contain " & sStr
End if
end Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced produced by
formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but
I
think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these
5)
that have something in them (it would be text), I want to check to
ensure
that the content is all the same, ignoring those that are blank.
Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1
have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc







--

Dave Peterson


--

Dave Peterson


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Checking Cell Contents

Yes, I did. Just copied your code and changed the cell addresses, so am not
sure why it's not working. Sorry....

"Dave Peterson" wrote:

Did you change this line:
set rng = Range("A1,B9,F2,A10,M3")
to the cell addresses that you wanted?

Paige wrote:

The active sheet is correct. I'm entering 'weekly', or 'monthly' or
'quarterly' in the cells, or nothing at all. So for those that have an
entry, they must match; if they do not match, I'm putting in a msgbox that
will pop up.

"Dave Peterson" wrote:

And is the activesheet the correct one?

Paige wrote:

Thanks, Tom. I cannot get this to work. Regardless of what I put into the
cells, it only returns the msgbox "All cells blank or contain other than text
constants". Any advice?

"Tom Ogilvy" wrote:

So I will assume the filled cells are constants (and not formulas

Sub CheckCells()
Dim rng as Range, rng1 as Range, cell as Range
Dim sStr as String
set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
set rng1 = rng.specialcells(xlconstants,xltextvalues)
On Error goto 0
if rng1 is nothing then
msgbox "All cells blank or contain other than text constants"
else
sStr = rng1(1)
for each cell in rng1
if cell.Value < sStr then
msgbox "Not all the same
exit sub
End if
Next
msgbox rng1.count & " cells all contain " & sStr
End if
end Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced produced by
formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but
I
think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these
5)
that have something in them (it would be text), I want to check to
ensure
that the content is all the same, ignoring those that are blank.
Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1
have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc







--

Dave Peterson


--

Dave Peterson

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Checking Cell Contents

It worked great for me.

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Yes, I did. Just copied your code and changed the cell addresses, so am

not
sure why it's not working. Sorry....

"Dave Peterson" wrote:

Did you change this line:
set rng = Range("A1,B9,F2,A10,M3")
to the cell addresses that you wanted?

Paige wrote:

The active sheet is correct. I'm entering 'weekly', or 'monthly' or
'quarterly' in the cells, or nothing at all. So for those that have

an
entry, they must match; if they do not match, I'm putting in a msgbox

that
will pop up.

"Dave Peterson" wrote:

And is the activesheet the correct one?

Paige wrote:

Thanks, Tom. I cannot get this to work. Regardless of what I put

into the
cells, it only returns the msgbox "All cells blank or contain

other than text
constants". Any advice?

"Tom Ogilvy" wrote:

So I will assume the filled cells are constants (and not

formulas

Sub CheckCells()
Dim rng as Range, rng1 as Range, cell as Range
Dim sStr as String
set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
set rng1 = rng.specialcells(xlconstants,xltextvalues)
On Error goto 0
if rng1 is nothing then
msgbox "All cells blank or contain other than text constants"
else
sStr = rng1(1)
for each cell in rng1
if cell.Value < sStr then
msgbox "Not all the same
exit sub
End if
Next
msgbox rng1.count & " cells all contain " & sStr
End if
end Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced

produced by
formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been

unsuccessful, but
I
think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those

cells (of these
5)
that have something in them (it would be text), I want to

check to
ensure
that the content is all the same, ignoring those that are

blank.
Note:
Sometimes all 5 cells could be blank, sometimes 4 could be

blank and 1
have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc







--

Dave Peterson


--

Dave Peterson



  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Checking Cell Contents

Thanks, Tom, Dave and Charlie. I'm obviously having problems....am sure it
is user error. I'll work on this again tomorrow with all your suggestions;
hopefully am thinking clearer then - it's been a long day.

Really appreciate all your help!

"Charlie" wrote:

This may not be too slick but it worked

Dim i As Long
Dim j As Long
Dim Cell As Range
Dim nCell As Long
Dim CellRef() As String

On Error Resume Next
Cells.SpecialCells(xlCellTypeConstants, xlTextValues).Select
If Selection.Count 1 Then
ReDim CellRef(Selection.Count)
For Each Cell In Selection
nCell = nCell + 1
CellRef(nCell) = Cell.Address(False, False)
Next Cell
For i = 1 To nCell - 1
For j = i + 1 To nCell
If Range(CellRef(i)).Value < Range(CellRef(j)).Value Then
MsgBox "Contents don't match in these cells: " & CellRef(i) & " " &
CellRef(j)
End If
Next j
Next i
End If


"Paige" wrote:

Thanks, Tom. I cannot get this to work. Regardless of what I put into the
cells, it only returns the msgbox "All cells blank or contain other than text
constants". Any advice?

"Tom Ogilvy" wrote:

So I will assume the filled cells are constants (and not formulas

Sub CheckCells()
Dim rng as Range, rng1 as Range, cell as Range
Dim sStr as String
set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
set rng1 = rng.specialcells(xlconstants,xltextvalues)
On Error goto 0
if rng1 is nothing then
msgbox "All cells blank or contain other than text constants"
else
sStr = rng1(1)
for each cell in rng1
if cell.Value < sStr then
msgbox "Not all the same
exit sub
End if
Next
msgbox rng1.count & " cells all contain " & sStr
End if
end Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced produced by
formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but
I
think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these
5)
that have something in them (it would be text), I want to check to
ensure
that the content is all the same, ignoring those that are blank.
Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1
have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc






  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Checking Cell Contents

I'd check those addresses one more time.

I'd bet dollars to doughnuts (hmmmm, doughnuts!) that it's a slap the forehead
moment when you figure out the problem.

Paige wrote:

Yes, I did. Just copied your code and changed the cell addresses, so am not
sure why it's not working. Sorry....

"Dave Peterson" wrote:

Did you change this line:
set rng = Range("A1,B9,F2,A10,M3")
to the cell addresses that you wanted?

Paige wrote:

The active sheet is correct. I'm entering 'weekly', or 'monthly' or
'quarterly' in the cells, or nothing at all. So for those that have an
entry, they must match; if they do not match, I'm putting in a msgbox that
will pop up.

"Dave Peterson" wrote:

And is the activesheet the correct one?

Paige wrote:

Thanks, Tom. I cannot get this to work. Regardless of what I put into the
cells, it only returns the msgbox "All cells blank or contain other than text
constants". Any advice?

"Tom Ogilvy" wrote:

So I will assume the filled cells are constants (and not formulas

Sub CheckCells()
Dim rng as Range, rng1 as Range, cell as Range
Dim sStr as String
set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
set rng1 = rng.specialcells(xlconstants,xltextvalues)
On Error goto 0
if rng1 is nothing then
msgbox "All cells blank or contain other than text constants"
else
sStr = rng1(1)
for each cell in rng1
if cell.Value < sStr then
msgbox "Not all the same
exit sub
End if
Next
msgbox rng1.count & " cells all contain " & sStr
End if
end Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced produced by
formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but
I
think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these
5)
that have something in them (it would be text), I want to check to
ensure
that the content is all the same, ignoring those that are blank.
Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1
have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc







--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Checking Cell Contents

Hi, Dave. I found out why it wasn't working. My spreadsheet is using merged
cells, with range names for each. It's ok with the range names themselves,
but not the fact that the cells are merged. Even if I reference them as
C1:D1,C3:D3, etc., it doesn't like that. Can this be fixed by changing
something in the code?

"Dave Peterson" wrote:

I'd check those addresses one more time.

I'd bet dollars to doughnuts (hmmmm, doughnuts!) that it's a slap the forehead
moment when you figure out the problem.

Paige wrote:

Yes, I did. Just copied your code and changed the cell addresses, so am not
sure why it's not working. Sorry....

"Dave Peterson" wrote:

Did you change this line:
set rng = Range("A1,B9,F2,A10,M3")
to the cell addresses that you wanted?

Paige wrote:

The active sheet is correct. I'm entering 'weekly', or 'monthly' or
'quarterly' in the cells, or nothing at all. So for those that have an
entry, they must match; if they do not match, I'm putting in a msgbox that
will pop up.

"Dave Peterson" wrote:

And is the activesheet the correct one?

Paige wrote:

Thanks, Tom. I cannot get this to work. Regardless of what I put into the
cells, it only returns the msgbox "All cells blank or contain other than text
constants". Any advice?

"Tom Ogilvy" wrote:

So I will assume the filled cells are constants (and not formulas

Sub CheckCells()
Dim rng as Range, rng1 as Range, cell as Range
Dim sStr as String
set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
set rng1 = rng.specialcells(xlconstants,xltextvalues)
On Error goto 0
if rng1 is nothing then
msgbox "All cells blank or contain other than text constants"
else
sStr = rng1(1)
for each cell in rng1
if cell.Value < sStr then
msgbox "Not all the same
exit sub
End if
Next
msgbox rng1.count & " cells all contain " & sStr
End if
end Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced produced by
formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but
I
think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these
5)
that have something in them (it would be text), I want to check to
ensure
that the content is all the same, ignoring those that are blank.
Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1
have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc







--

Dave Peterson


--

Dave Peterson


--

Dave Peterson



  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Checking Cell Contents

I understand that the message may come back as different when they're all the
same, but that doesn't say why you get the first message to appear.

Option Explicit

Sub CheckCells()
Dim rng As Range, rng1 As Range, cell As Range
Dim sStr As String
Dim cCtr As Long
Set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
Set rng1 = rng.SpecialCells(xlConstants, xlTextValues)
On Error GoTo 0
If rng1 Is Nothing Then
MsgBox "All cells blank or contain other than text constants"
Else
sStr = rng1(1)
cCtr = 0
For Each cell In rng1
If cell.MergeArea.Cells(1).Address = cell.Address Then
cCtr = cCtr + 1
If cell.MergeArea.Cells(1).Value < sStr Then
MsgBox "Not all the same"
Exit Sub
End If
End If
Next
MsgBox rng1.Count & " (" & cCtr & ")" & " cells all contain " & sStr
End If
End Sub

But merged cells are strange beasts.

If this doesn't help, I'd unmerge those merged cells and see if there is any
formula lingering in the former mergearea.

And as a tip, I'd always refer to the "merged" cell by the top left cell in that
range.



Paige wrote:

Hi, Dave. I found out why it wasn't working. My spreadsheet is using merged
cells, with range names for each. It's ok with the range names themselves,
but not the fact that the cells are merged. Even if I reference them as
C1:D1,C3:D3, etc., it doesn't like that. Can this be fixed by changing
something in the code?

"Dave Peterson" wrote:

I'd check those addresses one more time.

I'd bet dollars to doughnuts (hmmmm, doughnuts!) that it's a slap the forehead
moment when you figure out the problem.

Paige wrote:

Yes, I did. Just copied your code and changed the cell addresses, so am not
sure why it's not working. Sorry....

"Dave Peterson" wrote:

Did you change this line:
set rng = Range("A1,B9,F2,A10,M3")
to the cell addresses that you wanted?

Paige wrote:

The active sheet is correct. I'm entering 'weekly', or 'monthly' or
'quarterly' in the cells, or nothing at all. So for those that have an
entry, they must match; if they do not match, I'm putting in a msgbox that
will pop up.

"Dave Peterson" wrote:

And is the activesheet the correct one?

Paige wrote:

Thanks, Tom. I cannot get this to work. Regardless of what I put into the
cells, it only returns the msgbox "All cells blank or contain other than text
constants". Any advice?

"Tom Ogilvy" wrote:

So I will assume the filled cells are constants (and not formulas

Sub CheckCells()
Dim rng as Range, rng1 as Range, cell as Range
Dim sStr as String
set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
set rng1 = rng.specialcells(xlconstants,xltextvalues)
On Error goto 0
if rng1 is nothing then
msgbox "All cells blank or contain other than text constants"
else
sStr = rng1(1)
for each cell in rng1
if cell.Value < sStr then
msgbox "Not all the same
exit sub
End if
Next
msgbox rng1.count & " cells all contain " & sStr
End if
end Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced produced by
formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but
I
think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these
5)
that have something in them (it would be text), I want to check to
ensure
that the content is all the same, ignoring those that are blank.
Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1
have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc







--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Checking Cell Contents

Thanks, Dave; will work on this further. Really appreciate all your help -
have a great Christmas!

"Dave Peterson" wrote:

I understand that the message may come back as different when they're all the
same, but that doesn't say why you get the first message to appear.

Option Explicit

Sub CheckCells()
Dim rng As Range, rng1 As Range, cell As Range
Dim sStr As String
Dim cCtr As Long
Set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
Set rng1 = rng.SpecialCells(xlConstants, xlTextValues)
On Error GoTo 0
If rng1 Is Nothing Then
MsgBox "All cells blank or contain other than text constants"
Else
sStr = rng1(1)
cCtr = 0
For Each cell In rng1
If cell.MergeArea.Cells(1).Address = cell.Address Then
cCtr = cCtr + 1
If cell.MergeArea.Cells(1).Value < sStr Then
MsgBox "Not all the same"
Exit Sub
End If
End If
Next
MsgBox rng1.Count & " (" & cCtr & ")" & " cells all contain " & sStr
End If
End Sub

But merged cells are strange beasts.

If this doesn't help, I'd unmerge those merged cells and see if there is any
formula lingering in the former mergearea.

And as a tip, I'd always refer to the "merged" cell by the top left cell in that
range.



Paige wrote:

Hi, Dave. I found out why it wasn't working. My spreadsheet is using merged
cells, with range names for each. It's ok with the range names themselves,
but not the fact that the cells are merged. Even if I reference them as
C1:D1,C3:D3, etc., it doesn't like that. Can this be fixed by changing
something in the code?

"Dave Peterson" wrote:

I'd check those addresses one more time.

I'd bet dollars to doughnuts (hmmmm, doughnuts!) that it's a slap the forehead
moment when you figure out the problem.

Paige wrote:

Yes, I did. Just copied your code and changed the cell addresses, so am not
sure why it's not working. Sorry....

"Dave Peterson" wrote:

Did you change this line:
set rng = Range("A1,B9,F2,A10,M3")
to the cell addresses that you wanted?

Paige wrote:

The active sheet is correct. I'm entering 'weekly', or 'monthly' or
'quarterly' in the cells, or nothing at all. So for those that have an
entry, they must match; if they do not match, I'm putting in a msgbox that
will pop up.

"Dave Peterson" wrote:

And is the activesheet the correct one?

Paige wrote:

Thanks, Tom. I cannot get this to work. Regardless of what I put into the
cells, it only returns the msgbox "All cells blank or contain other than text
constants". Any advice?

"Tom Ogilvy" wrote:

So I will assume the filled cells are constants (and not formulas

Sub CheckCells()
Dim rng as Range, rng1 as Range, cell as Range
Dim sStr as String
set rng = Range("A1,B9,F2,A10,M3")
On Error Resume Next
set rng1 = rng.specialcells(xlconstants,xltextvalues)
On Error goto 0
if rng1 is nothing then
msgbox "All cells blank or contain other than text constants"
else
sStr = rng1(1)
for each cell in rng1
if cell.Value < sStr then
msgbox "Not all the same
exit sub
End if
Next
msgbox rng1.count & " cells all contain " & sStr
End if
end Sub

--
Regards,
Tom Ogilvy


"Paige" wrote in message
...
Tom, the blank cells are empty.

"Tom Ogilvy" wrote:

Are the blank cells empty or are the values produced produced by
formulas?

=if(condition,"","horse")

type of formula.
--
Regards,
Tom Ogilvy

"Paige" wrote in message
...
Can someone advise how to do this; so far have been unsuccessful, but
I
think
it should be easy to do.

Example: There are 5 non-contiguous cells; for those cells (of these
5)
that have something in them (it would be text), I want to check to
ensure
that the content is all the same, ignoring those that are blank.
Note:
Sometimes all 5 cells could be blank, sometimes 4 could be blank and 1
have
an entry, or 3 blank and 2 with an entry, etc.

Thanks for any help you can provide....pc







--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson

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
Checking the length of cell contents RichardG Excel Discussion (Misc queries) 8 February 21st 06 12:37 PM
checking a Cells contents Bob Kilmer Excel Programming 2 September 13th 04 06:41 AM
Auto-checking a checkbox based on cell contents. Ramon Cantu Jr. Excel Programming 2 May 27th 04 02:18 AM
Checking contents Edgar Thoemmes Excel Programming 4 February 9th 04 02:01 AM
Checking contents Edgar Thoemmes[_2_] Excel Programming 5 February 3rd 04 02:56 PM


All times are GMT +1. The time now is 11:50 PM.

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"