Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I test when a vaule is not found?

I am running a Do loop in which I want to locate all cells in the current
worksheet that have a colon in them.

I am also manipulating these cells as I go, concatenating everything before
the colon to cells below that have leading blanks. My code looks something
like this:

I first tried to put the cells.find function in the do while test thinking
that it would return a value, either boolean or numeric, but that failed.

Then I tried testing the cell location after each find. I made the
assumption that if the application did not find a new cell with the last
find that the activeCell would remain the same.

My problem is that I have not fount the right test to break out of the loop.

Can anyone help. I want to exit the loop when I can't find any other cells
with a colon in them.

=========================
Dim String1, String2, String3 As String
Range("A1").Activate
Cells.Find(What:=":", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=False).Activate
String1 = ActiveCell.Address
String2 = ""
Do While Not (String1 = String2)

Dim SearchString, SearchChar, MyPos As Variant
SearchString = ActiveCell.Value ' String to search in.
' ActiveCell.Value = ""
SearchChar = ":" ' Search for ":".

' A textual comparison starting at position 1.
MyPos = InStr(1, SearchString, SearchChar, 1)
String3 = Mid(SearchString, 1, MyPos - 1)
Do While (Mid(ActiveCell.Offset(1, 0).Value, 1, 1) = " ")
ActiveCell.Offset(1, 0).Activate
ActiveCell.Value = String3 + " " + LTrim(ActiveCell.Value)
Loop
String1 = ActiveCell.Address
Cells.Find(What:=":", After:=ActiveCell, LookIn:=xlValues, LookAt:=
_
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=False).Activate
If String1 < ActiveCell.Address Then
'reset String1
String1 = ActiveCell.Address
Else
String2 = ActiveCell.Address
End If

Loop

=========================


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default How do I test when a vaule is not found?

Hi

I've modified the loop so that you will breakout after you
have found all the colons. I've also modified a couple of
other places so that I would print something in a cell
that was 1 below the cell with the colon.

HTH

Tony
Dim String1, String2, String3 As String
Range("A1").Activate
Set c = Cells.Find(what:=":", After:=ActiveCell,
LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:=False)

If Not c Is Nothing Then
String1 = c.Address
String2 = ""
Do 'While Not (String1 = String2)

Dim SearchString, SearchChar, MyPos As Variant
SearchString = c.Value ' String to search in.
' ActiveCell.Value = ""
SearchChar = ":" ' Search for ":".

' A textual comparison starting at position 1.
MyPos = InStr(1, SearchString, SearchChar, 1)
String3 = Mid(SearchString, 1, MyPos - 1)
Do While (Mid(c.Offset(1, 0).Value, 1, 1) = " ")
Range(c).Offset(1, 0).Select

Loop
c.Offset(1, 0).Value = String3 + " " + LTrim
(ActiveCell.Value)
'String1 = ActiveCell.Address
' Cells.Find(what:=":", After:=ActiveCell,
LookIn:=xlValues, LookAt:= _
' xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:=False _
' ).Activate
Set c = Cells.FindNext(c)
' If String1 < c.Address Then
'reset String1
' String1 = ActiveCell.Address
' Else
' String2 = ActiveCell.Address
' End If

Loop While Not c Is Nothing And c.Address <
String1 'Until c.Address = String1
End If


-----Original Message-----
I am running a Do loop in which I want to locate all

cells in the current
worksheet that have a colon in them.

I am also manipulating these cells as I go, concatenating

everything before
the colon to cells below that have leading blanks. My

code looks something
like this:

I first tried to put the cells.find function in the do

while test thinking
that it would return a value, either boolean or numeric,

but that failed.

Then I tried testing the cell location after each find.

I made the
assumption that if the application did not find a new

cell with the last
find that the activeCell would remain the same.

My problem is that I have not fount the right test to

break out of the loop.

Can anyone help. I want to exit the loop when I can't

find any other cells
with a colon in them.

=========================
Dim String1, String2, String3 As String
Range("A1").Activate
Cells.Find(What:=":", After:=ActiveCell,

LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows,

SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=False).Activate
String1 = ActiveCell.Address
String2 = ""
Do While Not (String1 = String2)

Dim SearchString, SearchChar, MyPos As Variant
SearchString = ActiveCell.Value ' String to

search in.
' ActiveCell.Value = ""
SearchChar = ":" ' Search for ":".

' A textual comparison starting at position 1.
MyPos = InStr(1, SearchString, SearchChar, 1)
String3 = Mid(SearchString, 1, MyPos - 1)
Do While (Mid(ActiveCell.Offset(1, 0).Value, 1,

1) = " ")
ActiveCell.Offset(1, 0).Activate
ActiveCell.Value = String3 + " " + LTrim

(ActiveCell.Value)
Loop
String1 = ActiveCell.Address
Cells.Find(What:=":", After:=ActiveCell,

LookIn:=xlValues, LookAt:=
_
xlPart, SearchOrder:=xlByRows,

SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=False).Activate
If String1 < ActiveCell.Address Then
'reset String1
String1 = ActiveCell.Address
Else
String2 = ActiveCell.Address
End If

Loop

=========================


.

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
vlookup untill a vaule is found then automaticaly paste the result Aposto Excel Worksheet Functions 1 April 30th 08 04:42 PM
T Vaule function topnotchthrillr Excel Worksheet Functions 3 August 21st 06 04:16 PM
Find which values sum up another vaule, please help! samsg Excel Discussion (Misc queries) 0 February 27th 06 12:18 AM
Search for a test string and if found insert 'x' in clumn 'A' TCL Excel Discussion (Misc queries) 2 September 21st 05 05:18 PM


All times are GMT +1. The time now is 02:43 AM.

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"