Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Select a cell containing a word

If I have a cell that contains a word in cell A10, but may change to A15
sometimes, what vba code can find the first cell in a column containing
'"myword"?

Do I need to use offset?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Select a cell containing a word

Hi Scott

Sub test()
Dim x As String, r As Range
x = "myword"
Set r = Sheets("Sheet1").Columns("A:A")
If Application.CountIf(r, x) 0 Then _
r.Find(What:=x, LookIn:=xlFormulas, LookAt:=xlWhole).Activate
End Sub

--
XL2002
Regards

William



"scott" wrote in message
...
| If I have a cell that contains a word in cell A10, but may change to A15
| sometimes, what vba code can find the first cell in a column containing
| '"myword"?
|
| Do I need to use offset?
|
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Select a cell containing a word

This gives error below. What I'm tring to do is find the first cell that
contains 'myword', then select the rows from A1 to that cell minus 1 row.

Run-time error 91
object variable or with block variable not set


liam" wrote in message
...
Hi Scott

Sub test()
Dim x As String, r As Range
x = "myword"
Set r = Sheets("Sheet1").Columns("A:A")
If Application.CountIf(r, x) 0 Then _
r.Find(What:=x, LookIn:=xlFormulas, LookAt:=xlWhole).Activate
End Sub

--
XL2002
Regards

William



"scott" wrote in message
...
| If I have a cell that contains a word in cell A10, but may change to A15
| sometimes, what vba code can find the first cell in a column containing
| '"myword"?
|
| Do I need to use offset?
|
|




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Select a cell containing a word

Hi Scott

I assumed Column A contains hard data - if "myword" is a formula
relating to another cell, you may need to amend the code to...

Sub test()
Dim x As String, r As Range
x = "myword"
Set r = Sheets("Sheet1").Columns("A:A")
If Application.CountIf(r, x) 0 Then _
r.Find(What:=x, LookIn:=xlValues, LookAt:=xlWhole).Activate
End Sub

--
XL2002
Regards

William



"scott" wrote in message
...
| yes
|
| "William" wrote in message
| ...
| Hi Scott
|
| I've just retested and it works for me. Do you have Sheet1 selected?
| --
| XL2002
| Regards
|
| William
|
|

|
| "scott" wrote in message
| ...
| | This gives error below. What I'm tring to do is find the first cell
that
| | contains 'myword', then select the rows from A1 to that cell minus 1
| row.
| |
| | Run-time error 91
| | object variable or with block variable not set
| |
| |
| | liam" wrote in message
| | ...
| | Hi Scott
| |
| | Sub test()
| | Dim x As String, r As Range
| | x = "myword"
| | Set r = Sheets("Sheet1").Columns("A:A")
| | If Application.CountIf(r, x) 0 Then _
| | r.Find(What:=x, LookIn:=xlFormulas, LookAt:=xlWhole).Activate
| | End Sub
| |
| | --
| | XL2002
| | Regards
| |
| | William
| |
| |

| |
| | "scott" wrote in message
| | ...
| | | If I have a cell that contains a word in cell A10, but may change
to
| A15
| | | sometimes, what vba code can find the first cell in a column
| containing
| | | '"myword"?
| | |
| | | Do I need to use offset?
| | |
| | |
| |
| |
| |
| |
|
|
|
|
|




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
Word select from a string bridgjr Excel Worksheet Functions 3 August 4th 05 12:08 PM
Auto Word Select jimmy Excel Discussion (Misc queries) 0 April 25th 05 11:19 AM
Auto Word Select jimmy Excel Discussion (Misc queries) 0 April 25th 05 11:19 AM
auto word select jimmy Excel Discussion (Misc queries) 0 April 25th 05 11:07 AM
Find a certain word in excel and select the cell desmondleow[_8_] Excel Programming 3 December 18th 03 02:39 PM


All times are GMT +1. The time now is 02:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"