Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What code would:
1. Find & Select cells; 2. With NUMBERS; 3. Which are of 12 digits, i.e. = 100000000000 & <=999999999999? -- Best Regards, Faraz |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Just one thing which I noticed is that the below line should be
For Each cell In rngTemp 'instead of For Each cell In ActiveSheet.UsedRange But i dont see any probs other than that...Try in the activesheet itself and see If this post helps click Yes --------------- Jacob Skaria "Jacob Skaria" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Finding a number of values that adds up to a specific value | Excel Discussion (Misc queries) | |||
Finding cells with a specific number of characters | Excel Discussion (Misc queries) | |||
finding the number of rows and the first row with a specific value | Excel Programming | |||
finding the number of rows and the first row with a specific value | Excel Programming | |||
finding the number of rows and the first row with a specific value | Excel Programming |