Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Find all cell with a decimal value

I am in a blank sheet in a worksheet.

Is there a way to return all the cells within the worksheet that have a
value behind the decimal? For example: 1,245.00 would not be returned
because it is 0 after the decimal but 1,245.01 would be returned. I am only
looking for this to 2 decimal places.

Thank you,

Steven

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Find all cell with a decimal value

What do you want to do with the cells? Do you want to put them into an
Array, a Collection, highlight the cells, list the cell addresses in another
worksheet?
--
Cheers,
Ryan


"Steven" wrote:

I am in a blank sheet in a worksheet.

Is there a way to return all the cells within the worksheet that have a
value behind the decimal? For example: 1,245.00 would not be returned
because it is 0 after the decimal but 1,245.01 would be returned. I am only
looking for this to 2 decimal places.

Thank you,

Steven

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Find all cell with a decimal value

Try this:

Sub findum()
Dim r As Range
Set r = Nothing
For Each cel In ActiveSheet.UsedRange
v = cel.Value
If IsNumeric(v) And v < "" Then
If v - Int(v) < 0 Then
If r Is Nothing Then
Set r = cel
Else
Set r = Union(r, cel)
End If
End If
End If
Next
MsgBox r.Address
r.Select
End Sub
--
Gary''s Student - gsnu201001


"Steven" wrote:

I am in a blank sheet in a worksheet.

Is there a way to return all the cells within the worksheet that have a
value behind the decimal? For example: 1,245.00 would not be returned
because it is 0 after the decimal but 1,245.01 would be returned. I am only
looking for this to 2 decimal places.

Thank you,

Steven

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Find all cell with a decimal value

In this example, I built a loop to scan each cell in the used range in Sheet1
for values with decimals points. If the loop finds a decimal that doesn't
equal ".00" then it adds that cell to the collection. It will be up to you
to add code to do stuff to the collection. Let me know if you want help on
what you want to do with the collected cells. Hope this helps! If so, let
me know click "YES" below.

Sub FindDecimals()

Dim colMyCells As Collection
Dim cell As Range

Set colMyCells = New Collection

For Each cell In Sheets("Sheet1").UsedRange
If Right(cell.Text, 2) < "00" Then colMyCells.Add cell
Next cell

End Sub
--
Cheers,
Ryan


"Steven" wrote:

I am in a blank sheet in a worksheet.

Is there a way to return all the cells within the worksheet that have a
value behind the decimal? For example: 1,245.00 would not be returned
because it is 0 after the decimal but 1,245.01 would be returned. I am only
looking for this to 2 decimal places.

Thank you,

Steven

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Find all cell with a decimal value

I'm assuming your numbers are formatted to two decimal places because you
showed us the thousands separator in your example values (so that leads me
to believe your values are formatted... your last sentence leads me to
believe that as long as they are formatted, you have included the two
decimal places along with the thousands separator in that format). If the
only values on the (active) worksheet are numbers or blank cells, then you
can use this macro...

Sub FindDecimalNumbers()
Dim Cell As Range, U As Range
For Each Cell In ActiveSheet.UsedRange
If Cell.Text Like "*#.##" And (Not Cell.Text Like "*.00") Then
If U Is Nothing Then
Set U = Cell
Else
Set U = Union(U, Cell)
End If
End If
Next
U.Select
End Sub

If, on the other hand, you can have text values on the worksheet along with
your numbers AND some of those text values can end in a digit followed by a
dot followed by two more digits, then use this macro instead...

Sub FindDecimalNumbers()
Dim Cell As Range, U As Range, SC As Range
On Error Resume Next
Set SC = ActiveSheet.UsedRange.SpecialCells( _
xlCellTypeConstants, xlNumbers)
If SC Is Nothing Then Exit Sub
On Error GoTo 0
For Each Cell In SC
If Cell.Text Like "*.*" And (Not Cell.Text Like "*.00") Then
If U Is Nothing Then
Set U = Cell
Else
Set U = Union(U, Cell)
End If
End If
Next
U.Select
End Sub

--
Rick (MVP - Excel)


"Steven" wrote in message
...
I am in a blank sheet in a worksheet.

Is there a way to return all the cells within the worksheet that have a
value behind the decimal? For example: 1,245.00 would not be returned
because it is 0 after the decimal but 1,245.01 would be returned. I am
only
looking for this to 2 decimal places.

Thank you,

Steven


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
Find records with values more then 2 decimal places. Nicholas Excel Discussion (Misc queries) 3 April 3rd 23 10:56 AM
can not find align decimal points option Rae Drysdale Excel Discussion (Misc queries) 3 April 27th 06 09:47 PM
Converting 2-place decimal value to floating point decimal number with leading zero Kermit Piper Excel Discussion (Misc queries) 3 March 18th 06 06:20 PM
Find do not work with decimal point [email protected] Excel Programming 4 April 19th 05 12:12 PM
Show a time from one calculated cell as a decimal in another cell. KathyS Excel Worksheet Functions 1 January 20th 05 01:00 AM


All times are GMT +1. The time now is 11:25 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"