Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Search for text


Hi,

I have a problem, I have a worksheet which changes shape quite a bit
when different data is loaded into it and I need to be able to locate
cells so I can use formula on them as part of a larger macro.

How can I locate the cell which is two to the left of the cell which
will always contain the words 'Total Life Sales'.

I was thinking this is something to do with an active cell value =
'Total Life Sales' and then offset two the the left, but i'm not sure
how to phrase it.

Any help would be grand

Cheers

Hayley


--
Hru48
------------------------------------------------------------------------
Hru48's Profile: http://www.excelforum.com/member.php...o&userid=24895
View this thread: http://www.excelforum.com/showthread...hreadid=541618

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Search for text

If you haven't found your answer yet, you could try something like this:

Dim rngCell As Range
With Sheet1
Set rngCell = .Cells.Find( _
What:="Total Life Sales", _
After:=.Range("A1"), _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext _
).Offset(0, -2)
End With

You can then use rngCell as the cell that is 2 left of "Total Life Sales"
(ex. rngCell.Select or rngCell.Value = ""). Note that if it does not find
"Total Life Sales", it will give you a runtime error.

"Hru48" wrote:


Hi,

I have a problem, I have a worksheet which changes shape quite a bit
when different data is loaded into it and I need to be able to locate
cells so I can use formula on them as part of a larger macro.

How can I locate the cell which is two to the left of the cell which
will always contain the words 'Total Life Sales'.

I was thinking this is something to do with an active cell value =
'Total Life Sales' and then offset two the the left, but i'm not sure
how to phrase it.

Any help would be grand

Cheers

Hayley


--
Hru48
------------------------------------------------------------------------
Hru48's Profile: http://www.excelforum.com/member.php...o&userid=24895
View this thread: http://www.excelforum.com/showthread...hreadid=541618


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default Search for text

Try this:
If activecell.value = "Total Life Sales" then
Activecell.offset(0,-1).select
End if




"Hru48" wrote:


Hi,

I have a problem, I have a worksheet which changes shape quite a bit
when different data is loaded into it and I need to be able to locate
cells so I can use formula on them as part of a larger macro.

How can I locate the cell which is two to the left of the cell which
will always contain the words 'Total Life Sales'.

I was thinking this is something to do with an active cell value =
'Total Life Sales' and then offset two the the left, but i'm not sure
how to phrase it.

Any help would be grand

Cheers

Hayley


--
Hru48
------------------------------------------------------------------------
Hru48's Profile: http://www.excelforum.com/member.php...o&userid=24895
View this thread: http://www.excelforum.com/showthread...hreadid=541618


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Search for text


Thats great - many many thanks


--
Hru48
------------------------------------------------------------------------
Hru48's Profile: http://www.excelforum.com/member.php...o&userid=24895
View this thread: http://www.excelforum.com/showthread...hreadid=541618

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Search for text

It doesn't seem like my previous reply posted properly...

I wanted to let you know that if you haven't found an answer yet, you can
try something like this:

Dim rngCell As Range
With Sheet1 'Change this to the appropriate sheet name
Set rngCell = .Cells.Find( _
What:="Total Life Sales", _
After:=.Range("A1"), _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext _
).Offset(0, -2)
End With

You can then use rngCell as the cell that's 2 left of "Total Life Sales".
Note that if it does not find "Total Life Sales", you will get a runtime
error.

"Hru48" wrote:


Hi,

I have a problem, I have a worksheet which changes shape quite a bit
when different data is loaded into it and I need to be able to locate
cells so I can use formula on them as part of a larger macro.

How can I locate the cell which is two to the left of the cell which
will always contain the words 'Total Life Sales'.

I was thinking this is something to do with an active cell value =
'Total Life Sales' and then offset two the the left, but i'm not sure
how to phrase it.

Any help would be grand

Cheers

Hayley


--
Hru48
------------------------------------------------------------------------
Hru48's Profile: http://www.excelforum.com/member.php...o&userid=24895
View this thread: http://www.excelforum.com/showthread...hreadid=541618


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
search for text then return text r2rcode Excel Worksheet Functions 1 March 3rd 10 07:23 PM
Nested formula to search a text string and return specific text Barbie Excel Worksheet Functions 10 February 21st 09 07:40 AM
Fun with text functions - search for text mr tom Excel Worksheet Functions 7 October 26th 07 07:17 PM
Search, find or lookup defined text in text string zzxxcc Excel Worksheet Functions 9 September 6th 07 09:37 PM
Search for text, copy the number in front of text w0cyru01 Excel Programming 4 August 3rd 05 05:15 PM


All times are GMT +1. The time now is 03:17 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"