Dear Excel users,
I would like to use the find function, but it doesn't work properly just yet.
My wishes are:
* The cell that has to be found contains a reference to another cell (e.g. =L3).
* The cell that has to be found has a width of 0,1. So the text is not visible in the cell.
With LookIn:=xlFormulas the cell with a reference isn't found, the cell with the original value is found also with a width of the cell of 0,1.
With LookIn:=xlValues both cells are found, but none of the cells are found when the width is 0,1.
A concised example is attached. The macro is given in the following quote.
Hopefully someone has a suggestion?Sub ProFindCell() Dim findCell As Double 'findCell is the value to be found in cell B3 findCell = Range("B3").Value 'CDate is used to convert findCell in a date format Cells.Find(What:=CDate(findCell), After:=ActiveCell, LookIn:=xlValues, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate MsgBox ActiveCell.Column 'Eventually I would like to have the column number of the found cell. Exit Sub End Sub
Thanks! Wiggert
Last edited by teylyn; 12-22-2009 at 07:55 PM. Reason: changed quote to code tags
Since you're using code anyways why not just expand the column(s) and then put them back to the width you want. You can turn off the screen updating so the user can't see what's going on.
Dear jrdnoland,
Maybe that will be the best and only solution there is, because I still haven't found a clue to get the job done otherwise.Since you're using code anyways why not just expand the column(s) and then put them back to the width you want. You can turn off the screen updating so the user can't see what's going on.
Thanks for the reply and the idea!
Maybe someone else has the master solution??
Cheers, Wiggert
Hello Wiggert,
Try this...
Sub ProFindCell() Dim findCell As Double 'findCell is the value to be found in cell B3 findCell = Range("B3").Value 'CDate is used to convert findCell in a date format Cells.Find(What:=CDate("*" & findCell.Text & "*"), After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate MsgBox ActiveCell.Column 'Eventually I would like to have the column number of the found cell. Exit Sub End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Hello Leith,
Thanks for the reply!
I'm getting a compile error: Unvalid qualification.
What would be the purpose of the "*" code?
Also:
Dim findCell As string
findCell = Range("B3").text
gives the same error.
And:
CDate("*" & findCell & "*") gives the error in dutch; typen komen niet overeen. The translation would be something as The types don't match.
Hope you know what the problem is?because I do not..
Thanks! Wiggert
Hello Wiggert,
The asterisk is used as a "wildcard" character in the Find function. It means match zero or more characters.
This piece of code:
retrieves the cell text, the formatted part that you see on the worksheet.findCell.Text
This line
is generating error because I used the wrong syntax. The wildcard characters are not legal date characters. Change it to this...CDate("*" & findCell & "*")
"*" & findCell & "*"
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Hello Leith,
Thanks for the thorough explanation.
It still isn't working. I used this code:
I'm getting the error that the objectvariable or blockvariable With isn't given.Sub ProFindCell() Dim findCell As Double findCell = Range("B3").Value Cells.Find(What:=("*" & findCell & "*"), After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate MsgBox ActiveCell.Column End Sub
This ussualy implies that the find function hasn't found anything, right?
It is a logic reaction I think, because findCell is now a value (e.g. 38765) and the cells in the sheet only contain date formatted values.
Also when I use findcell as a string:
The macro also returns the error objectvariable or ... etc. isn't found, allthough findCell has the 'value' "1-1-2009". So why doesn't it find a value in the sheet without cDate then?Sub ProFindCell() Dim findCell As String findCell = Range("B3").Text Cells.Find(What:=("*" & findCell & "*"), After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate MsgBox ActiveCell.Column End Sub
Any suggestions?
Thanks again! Wiggert
Hello Wiggert,
It would easier for me to troubleshoot the problem using the original data. Can you post your workbook? I am using Excel 2003.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Hi Leith,
Isn't that the .xlsm file I attached in my first post? Can you open that file with excel 2003?
That file hasn't changed since then.
I also attached a .xls file.
Thanks for the effort!
Wiggert
Hello Wiggert,
Excel 2003 can read 2007 files with some upgrades, but I haven't gotten them yet. The xls file I can read. Thanks for posting it.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Hello Wiggert,
Here is what I have found. The Find function will miss cells if the data can not be displayed in full. Both xlFormulas and xlValues settings are affected the same way. So, I need to develop a "Plan B" using VBA to locate thiese cells in a fast and efficient manner, regardless of the cell size or if they are not visible.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Exactly!
And I was hoping there would be a simple solution for this.
I'm hoping you'll come up with a great solution!
Merry Christmas everybody!
Wiggert
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks