Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default User-defined search term in macro

I'm trying to pull a range of rows out of a sheet based on the value in
one of the columns being the same. As the value itself will change for
each time I run the macro, I need to be able to define a different
value each time - but I don't want to have to go in and amend the macro
every time.

So the macro starts with an input box where I enter the value the
routine should search for. However although vResponse is being set as
the value I enter and on the face of it the cell value and the inputted
variable match, the lines are not being pulled out.

Dim vResponse As Variant
vResponse = Application.InputBox( _
Prompt:="Enter Batch Number", _
Default:=Format(Number, 0), _
Type:=2)
'If vResponse = False Then 'User cancelled

Dim myRng2 As Range
Dim myCell2 As Range
Dim HoldRng2 As Range

Set myRng2 = Range("B1:B65536")

For Each myCell2 In myRng2.Cells
If myCell2.Value = vResponse Then ' The macro is going
straight from this line to the next
If HoldRng2 Is Nothing Then ' cell even though
myCell2.Value and vResponse are
Set HoldRng2 = myCell2 ' the same.
Else
Set HoldRng2 = Union(myCell2, HoldRng2)
End If
End If
Next myCell2

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default User-defined search term in macro

A bit clearer...

Dim vResponse As Variant
vResponse = Application.InputBox( _
Prompt:="Enter Batch Number", _
Default:=Format(Number, 0), _
Type:=2)
'If vResponse = False Then 'User cancelled

Dim myRng2 As Range
Dim myCell2 As Range
Dim HoldRng2 As Range

Set myRng2 = Range("B1:B65536")

For Each myCell2 In myRng2.Cells
If myCell2.Value = vResponse Then
If HoldRng2 Is Nothing Then
Set HoldRng2 = myCell2
Else
Set HoldRng2 = Union(myCell2, HoldRng2)
End If
End If
Next myCell2

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,886
Default User-defined search term in macro

Hi

With vResponse set as a variant, if your Batchnumbers in column B are
numeric, then the comparison will return false.
Try adding a line, vResponse = vResponse * 1
before going through the loop.

--
Regards

Roger Govier


"Rokuro kubi" wrote in message
ups.com...
A bit clearer...

Dim vResponse As Variant
vResponse = Application.InputBox( _
Prompt:="Enter Batch Number", _
Default:=Format(Number, 0), _
Type:=2)
'If vResponse = False Then 'User cancelled

Dim myRng2 As Range
Dim myCell2 As Range
Dim HoldRng2 As Range

Set myRng2 = Range("B1:B65536")

For Each myCell2 In myRng2.Cells
If myCell2.Value = vResponse Then
If HoldRng2 Is Nothing Then
Set HoldRng2 = myCell2
Else
Set HoldRng2 = Union(myCell2, HoldRng2)
End If
End If
Next myCell2



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default User-defined search term in macro

Great Roger thanks

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 can second, third user sign excel file containing macro Sevgi Excel Discussion (Misc queries) 0 November 10th 06 03:23 PM
error when running cut & paste macro Otto Moehrbach Excel Worksheet Functions 4 August 9th 06 01:49 PM
Writing macro results to user defined areas within excel gauss1976 Excel Discussion (Misc queries) 1 July 27th 06 01:35 PM
How to stop Excel remembering/loading macro from previously opened Workbook Norman Yuan Excel Discussion (Misc queries) 4 June 17th 06 04:13 PM
user defined function row number bj Excel Worksheet Functions 11 March 9th 05 01:31 PM


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