Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Excel 97 search macro help please

Hello,

I am trying to get the below macro to search column H of my workbook. It
works fine but i'd need it to also search columns: J, L, N, P, R, T. All
these columns have asset numbers.

Could someone please help me modifiy my existing code so that this may
happen.

All help is greatly appreciated.

Kind regards,

Chris.




Sub AssetNoSearch()
'
'AssetNoSearch Macro
'
'
Dim Found As Range
Dim Sh As Worksheet
Dim SheetsToCheck As Variant
Dim AssetNumber As String


Application.ScreenUpdating = False

SheetsToCheck = Array("DTP Hardware")

AssetNumber = Application.InputBox("Please Enter The Asset Number You
Wish to Locate and either click on the <OK button and then hit <ENTER or
hit <ENTER twice: ", _
"Find Asset Number")

For Each Sh In Sheets(SheetsToCheck)
Set Found = Sh.Columns("H").Find(AssetNumber, _
LookIn:=xlFormulas, _
Lookat:=xlPart)
If Not Found Is Nothing Then
Found.Parent.Activate
Found.Activate
Exit For
End If
Next Sh


If Found Is Nothing Then
MsgBox "Asset Number: " & AssetNumber & " does not exist."
End If
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Excel 97 search macro help please

Chris,
Not tested but try,
Option Base 1
Sub AssetNoSearch()
'
'AssetNoSearch Macro
'
'
Dim Found As Range
Dim Sh As Worksheet
Dim SheetsToCheck As Variant
Dim AssetNumber As String
Dim myarray As Variant
Dim mycnt As Integer
myarray = Array("H", "L", "N", "P", "R", "T")
Application.ScreenUpdating = False

SheetsToCheck = Array("DTP Hardware")

AssetNumber = Application.InputBox("Please Enter The Asset Number You _
Wish to Locate and either click on the <OK button and then hit <ENTER or _
hit <ENTER twice: ", _
"Find Asset Number")
For mycnt = 1 To UBound(myarray)
For Each Sh In Sheets(SheetsToCheck)
Set Found = Sh.Columns(myarray(mycnt)).Find(AssetNumber, _
LookIn:=xlFormulas, _
Lookat:=xlPart)
If Not Found Is Nothing Then
Found.Parent.Activate
Found.Activate
Exit For
End If
Next Sh
Next mycnt
If Found Is Nothing Then
MsgBox "Asset Number: " & AssetNumber & " does not exist."
End If
End Sub



"Chris Hankin" wrote in message
...
Hello,

I am trying to get the below macro to search column H of my workbook. It
works fine but i'd need it to also search columns: J, L, N, P, R, T. All
these columns have asset numbers.

Could someone please help me modifiy my existing code so that this may
happen.

All help is greatly appreciated.

Kind regards,

Chris.




Sub AssetNoSearch()
'
'AssetNoSearch Macro
'
'
Dim Found As Range
Dim Sh As Worksheet
Dim SheetsToCheck As Variant
Dim AssetNumber As String


Application.ScreenUpdating = False

SheetsToCheck = Array("DTP Hardware")

AssetNumber = Application.InputBox("Please Enter The Asset Number You
Wish to Locate and either click on the <OK button and then hit <ENTER or
hit <ENTER twice: ", _
"Find Asset Number")

For Each Sh In Sheets(SheetsToCheck)
Set Found = Sh.Columns("H").Find(AssetNumber, _
LookIn:=xlFormulas, _
Lookat:=xlPart)
If Not Found Is Nothing Then
Found.Parent.Activate
Found.Activate
Exit For
End If
Next Sh


If Found Is Nothing Then
MsgBox "Asset Number: " & AssetNumber & " does not exist."
End If
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Excel 97 search macro help please

Thanks Charles for you prompt reply - much appreciated.

Unfortunately, I was unable to get your modified code to work. I even
tried using the F8-key in the Visual Basic Editor of Excel 97 and went
through line-by-line of code.

I am not sure but possibly myarray does not work all that well - but I
am only taking a educated guess.

I was wondering if maybe you could please take another look at it or on
your request, I could send you my spreadsheet to look at - it's very
basic.

Kind regards,

Chris.

Live Long and Prosper :)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Excel 97 search macro help please

does it help to put the mycnt loop inside of the Sh loop:

For Each Sh In Sheets(SheetsToCheck)
For mycnt = 1 To UBound(myarray)

Set Found = Sh.Columns(myarray(mycnt)).Find(AssetNumber, _
LookIn:=xlFormulas, _
Lookat:=xlPart)
If Not Found Is Nothing Then
Found.Parent.Activate
Found.Activate
Exit For
End If

Next mycnt
Next Sh

"Charles Harmon" wrote:

Chris,
Not tested but try,
Option Base 1
Sub AssetNoSearch()
'
'AssetNoSearch Macro
'
'
Dim Found As Range
Dim Sh As Worksheet
Dim SheetsToCheck As Variant
Dim AssetNumber As String
Dim myarray As Variant
Dim mycnt As Integer
myarray = Array("H", "L", "N", "P", "R", "T")
Application.ScreenUpdating = False

SheetsToCheck = Array("DTP Hardware")

AssetNumber = Application.InputBox("Please Enter The Asset Number You _
Wish to Locate and either click on the <OK button and then hit <ENTER or _
hit <ENTER twice: ", _
"Find Asset Number")
For mycnt = 1 To UBound(myarray)
For Each Sh In Sheets(SheetsToCheck)
Set Found = Sh.Columns(myarray(mycnt)).Find(AssetNumber, _
LookIn:=xlFormulas, _
Lookat:=xlPart)
If Not Found Is Nothing Then
Found.Parent.Activate
Found.Activate
Exit For
End If
Next Sh
Next mycnt
If Found Is Nothing Then
MsgBox "Asset Number: " & AssetNumber & " does not exist."
End If
End Sub



"Chris Hankin" wrote in message
...
Hello,

I am trying to get the below macro to search column H of my workbook. It
works fine but i'd need it to also search columns: J, L, N, P, R, T. All
these columns have asset numbers.

Could someone please help me modifiy my existing code so that this may
happen.

All help is greatly appreciated.

Kind regards,

Chris.




Sub AssetNoSearch()
'
'AssetNoSearch Macro
'
'
Dim Found As Range
Dim Sh As Worksheet
Dim SheetsToCheck As Variant
Dim AssetNumber As String


Application.ScreenUpdating = False

SheetsToCheck = Array("DTP Hardware")

AssetNumber = Application.InputBox("Please Enter The Asset Number You
Wish to Locate and either click on the <OK button and then hit <ENTER or
hit <ENTER twice: ", _
"Find Asset Number")

For Each Sh In Sheets(SheetsToCheck)
Set Found = Sh.Columns("H").Find(AssetNumber, _
LookIn:=xlFormulas, _
Lookat:=xlPart)
If Not Found Is Nothing Then
Found.Parent.Activate
Found.Activate
Exit For
End If
Next Sh


If Found Is Nothing Then
MsgBox "Asset Number: " & AssetNumber & " does not exist."
End If
End Sub





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Excel 97 search macro help please

Thanks Gocush - that loop worked very well - thanks very much - greatly
appreciated.

Kind regards,

Chris.

Live Long and Prosper :)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
How do I set up a search macro in Excel? Jacaara Excel Discussion (Misc queries) 1 February 23rd 06 08:51 PM
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Excel XP VBA code to search all macro code in Excel module for specific search string criteria Ed[_18_] Excel Programming 4 May 20th 04 02:08 PM
Excel XP VBA code to search all macro code in Excel module for specific search string criteria Frank Kabel Excel Programming 0 May 19th 04 08:11 PM
Excel VBA to search all macro code in Excel module for specific string criteria Roger1947 Excel Programming 0 May 19th 04 05:51 PM


All times are GMT +1. The time now is 12:26 PM.

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"