View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default Finding A Number Existing Between A Specific Range?

I have tried the below with around 12 numbers satisfying the condition
scattered within the range..and found to be working fine...Just put a message
box to see what strAddress returns..

Sub Macro1()
Dim strAddress As String, cell As Range
Dim rngTemp As Range
Set rngTemp = Range("A1:K30")
If WorksheetFunction.CountIf(rngTemp, "" & (10 ^ 10) * 10) - _
WorksheetFunction.CountIf(rngTemp, "" & (10 ^ 10) * 100) 0 Then

For Each cell In ActiveSheet.UsedRange
If Not cell.HasFormula Then
If cell.Value = (10 ^ 10) * 10 And _
cell.Value < (10 ^ 10) * 100 Then _
strAddress = strAddress & "," & cell.Address
End If
Next

End If
If strAddress < "" Then Range(Mid(strAddress, 2)).Select
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Faraz A. Qureshi" wrote:

Thanx Jacob,

However, Error 1004, with
Range(Mid(strAddress, 2)).Select
highlighted is being faced.
--
Best Regards,

Faraz


"Jacob Skaria" wrote:

Faraz, you can try using COUNTIF() in from to check whether any number
exits..Advantages are..

--you can avoid the looping if there are no numbers...
--you can Exit the loop once the count is reached.

Sub Macro1()
Dim strAddress As String, cell As Range
Dim rngTemp As Range
Set rngTemp = Range("A1:J30")
If WorksheetFunction.CountIf(rngTemp, "" & (10 ^ 10) * 10) - _
WorksheetFunction.CountIf(rngTemp, "" & (10 ^ 10) * 100) 0 Then

For Each cell In ActiveSheet.UsedRange
If cell.Value = (10 ^ 10) * 10 And _
cell.Value < (10 ^ 10) * 100 Then _
strAddress = strAddress & "," & cell.Address
Next
End If

If strAddress < "" Then Range(Mid(strAddress, 2)).Select
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Hi Again

One way is to check the cell value and store the address in a string and
select at the end. There should be a much better way.

Sub Macro()
Dim strAddress As String, cell As Range
For Each cell In ActiveSheet.UsedRange
If cell.Value 100000000000# Then _
strAddress = strAddress & "," & cell.Address
Next
If strAddress < "" Then Range(Mid(strAddress, 2)).Select
End Sub

PS: You can modify the condition to suit

If this post helps click Yes
---------------
Jacob Skaria


"Faraz A. Qureshi" wrote:

What code would:
1. Find & Select cells;
2. With NUMBERS;
3. Which are of 12 digits, i.e. = 100000000000 & <=999999999999?
--
Best Regards,

Faraz