Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Searching and storing Column Number

Hi,

Is there a way in VB I can search for a word in an excel file, and
then once found I store the column number of the cell where the word
is found?


Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Searching and storing Column Number

One way:
Sub oneWay()
Dim r As Long
Dim sString As String
sString = "fred"
On Error Resume Next
r = Cells.Find(What:=sString, After:=Cells(1, 1), _
LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Column
On Error GoTo 0
If r = 0 Then
MsgBox "not found"
Else
MsgBox r
End If
End Sub

wrote:
Hi,

Is there a way in VB I can search for a word in an excel file, and
then once found I store the column number of the cell where the word
is found?


Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Searching and storing Column Number

Thanks,

I tried that and I keep getting 1 as my answer but that's not where
the word is found..

Any idea why?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Searching and storing Column Number

Did you look through column A to see if your string was anywhere in that column?

If you did, you may want to post your code and some details about what's in your
worksheet and where.

wrote:

Thanks,

I tried that and I keep getting 1 as my answer but that's not where
the word is found..

Any idea why?


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Searching and storing Column Number

My Macro is exactly as JW wrote it: nothing before or after... also,
there's only one occurance of the word.

Thanks

On Sep 28, 2:16 pm, Dave Peterson wrote:
Did you look through column A to see if your string was anywhere in that column?

If you did, you may want to post your code and some details about what's in your
worksheet and where.

wrote:

Thanks,


I tried that and I keep getting 1 as my answer but that's not where
the word is found..


Any idea why?


--

Dave Peterson





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Searching and storing Column Number

Sub oneWay()
Dim r As Range
Dim sString As String


sString = "fred" ' change this to the word you are looking for

set r = Cells.Find(What:=sString, _
After:=Cells(rows.count, columns.count), _
LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)

If r is nothing then
MsgBox "not found"
Else
application.Goto r, true
MsgBox r.column
End If
End Sub

--
Regards,
Tom Ogilvy

" wrote:

My Macro is exactly as JW wrote it: nothing before or after... also,
there's only one occurance of the word.

Thanks

On Sep 28, 2:16 pm, Dave Peterson wrote:
Did you look through column A to see if your string was anywhere in that column?

If you did, you may want to post your code and some details about what's in your
worksheet and where.

wrote:

Thanks,


I tried that and I keep getting 1 as my answer but that's not where
the word is found..


Any idea why?


--

Dave Peterson




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
Searching for low and high number Mortir Excel Worksheet Functions 13 January 25th 09 08:00 PM
Storing column() to use later Marco Excel Programming 7 November 22nd 06 11:55 PM
storing lettrs in an excel cell to later = a number for a formula diydan48 Excel Discussion (Misc queries) 1 October 15th 06 09:16 PM
Storing column references in a variable Conan Kelly[_2_] Excel Programming 3 June 29th 05 05:15 PM
Storing a column of input data Don Kline[_3_] Excel Programming 2 April 13th 05 02:12 PM


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