Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
RPTZ
 
Posts: n/a
Default Macro Code minor alteration please.


I was shown a code and I think it was misunderstood.
Not sure how to slighty modify the part of the code to do a search.

It was suppose to search for the value in Sheet1 A1 ( fixed location)
in Sheet 2 "anywhere"

So if the macro is running and it reaches the point to find the value
of Sheet 1 A1, then Select Sheet 2, find the same value anywhere in
Sheet 2, and then select that cell.
From there I have the rest covered after the End If

The code I was shown looks like this:
-----------------------------------------------

Sub Find_First()
Dim FindString As String
Dim Rng As Range
FindString = InputBox("Enter a Search value")

If Trim(FindString) < "" Then
Set Rng = Range("A:A").find(What:=FindString, _
After:=Range("A" & Rows.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.Goto Rng, True
Else
MsgBox "Nothing found"
End If
End If
End Sub ( or continue with the rest of the macro)

But the misunderstanding was where it shows;

FindString = InputBox("Enter a Search value")

This means it has to be typed in. There is no need to type in the
value, it is always in the same location.
It changes value, is when the macro was activated before anyway.

How can I then make that piece of macro code, go to Sheet 2 and locate
the same value as in Sheet 1 A1 without requireinf to type in a value
?

Much appreciated


--
RPTZ
------------------------------------------------------------------------
RPTZ's Profile: http://www.excelforum.com/member.php...o&userid=24896
View this thread: http://www.excelforum.com/showthread...hreadid=384329

  #2   Report Post  
Bob Umlas, Excel MVP
 
Posts: n/a
Default

change
FindString = InputBox("Enter a Search value")
to
FindString = Sheets("A1").range("A1").value

"RPTZ" wrote:


I was shown a code and I think it was misunderstood.
Not sure how to slighty modify the part of the code to do a search.

It was suppose to search for the value in Sheet1 A1 ( fixed location)
in Sheet 2 "anywhere"

So if the macro is running and it reaches the point to find the value
of Sheet 1 A1, then Select Sheet 2, find the same value anywhere in
Sheet 2, and then select that cell.
From there I have the rest covered after the End If

The code I was shown looks like this:
-----------------------------------------------

Sub Find_First()
Dim FindString As String
Dim Rng As Range
FindString = InputBox("Enter a Search value")

If Trim(FindString) < "" Then
Set Rng = Range("A:A").find(What:=FindString, _
After:=Range("A" & Rows.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.Goto Rng, True
Else
MsgBox "Nothing found"
End If
End If
End Sub ( or continue with the rest of the macro)

But the misunderstanding was where it shows;

FindString = InputBox("Enter a Search value")

This means it has to be typed in. There is no need to type in the
value, it is always in the same location.
It changes value, is when the macro was activated before anyway.

How can I then make that piece of macro code, go to Sheet 2 and locate
the same value as in Sheet 1 A1 without requireinf to type in a value
?

Much appreciated


--
RPTZ
------------------------------------------------------------------------
RPTZ's Profile: http://www.excelforum.com/member.php...o&userid=24896
View this thread: http://www.excelforum.com/showthread...hreadid=384329


  #3   Report Post  
RPTZ
 
Posts: n/a
Default


Thanks, it did not seem to work either.

I get a error/debug alert saying:

"Subscripit out of range"

It has to be whatever the value is in "Sheet 1. A1"
then to locate that same value in Sheet 2. and go to the Cell location
in Sheet 2

Once it finds the same value in any cell range within Sheet 2, it
continues
with;
Selection.Offset(1, 0).Select '*Down*
Selection.Copy
Etc Etc,

It will help alot with accuracy if the values do not have to be typed
in.

Much appreciated.


--
RPTZ
------------------------------------------------------------------------
RPTZ's Profile: http://www.excelforum.com/member.php...o&userid=24896
View this thread: http://www.excelforum.com/showthread...hreadid=384329

  #4   Report Post  
Bob Phillips
 
Posts: n/a
Default

Bob probably meant FindString = Sheets("Sheet1").range("A1").value


--
HTH

Bob Phillips

"RPTZ" wrote in message
...

Thanks, it did not seem to work either.

I get a error/debug alert saying:

"Subscripit out of range"

It has to be whatever the value is in "Sheet 1. A1"
then to locate that same value in Sheet 2. and go to the Cell location
in Sheet 2

Once it finds the same value in any cell range within Sheet 2, it
continues
with;
Selection.Offset(1, 0).Select '*Down*
Selection.Copy
Etc Etc,

It will help alot with accuracy if the values do not have to be typed
in.

Much appreciated.


--
RPTZ
------------------------------------------------------------------------
RPTZ's Profile:

http://www.excelforum.com/member.php...o&userid=24896
View this thread: http://www.excelforum.com/showthread...hreadid=384329



  #5   Report Post  
RPTZ
 
Posts: n/a
Default


No, tried a few variations, not working.

I think it's best if anyone has a go, to just open a Workbook, 2
sheets as I have described in the example and try, rather than what
seems to be a guess.

Thanks


--
RPTZ
------------------------------------------------------------------------
RPTZ's Profile: http://www.excelforum.com/member.php...o&userid=24896
View this thread: http://www.excelforum.com/showthread...hreadid=384329



  #6   Report Post  
JMB
 
Posts: n/a
Default

I noticed in your previous post you referred to Sheet1 as "Sheet1" and "Sheet
1"

Nothing wrong with Bob's code. I think you just need to decide on what the
sheet is named.

"RPTZ" wrote:


No, tried a few variations, not working.

I think it's best if anyone has a go, to just open a Workbook, 2
sheets as I have described in the example and try, rather than what
seems to be a guess.

Thanks


--
RPTZ
------------------------------------------------------------------------
RPTZ's Profile: http://www.excelforum.com/member.php...o&userid=24896
View this thread: http://www.excelforum.com/showthread...hreadid=384329


  #7   Report Post  
JMB
 
Posts: n/a
Default

My last post got wrapped in a bad spot. The second worksheet name is
supposed to be

"Sheet 1"



"RPTZ" wrote:


No, tried a few variations, not working.

I think it's best if anyone has a go, to just open a Workbook, 2
sheets as I have described in the example and try, rather than what
seems to be a guess.

Thanks


--
RPTZ
------------------------------------------------------------------------
RPTZ's Profile: http://www.excelforum.com/member.php...o&userid=24896
View this thread: http://www.excelforum.com/showthread...hreadid=384329


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
Macro as multiple use code Bruce Neylon New Users to Excel 6 June 29th 05 06:11 PM
is there anyway to make it so the users of my excel spread sheet cant view the macro code w/o a password? Daniel Excel Worksheet Functions 2 June 28th 05 05:34 AM
Make Change Case in Excel a format rather than formula Kevin Excel Worksheet Functions 1 March 18th 05 08:53 PM
macro code shortcut Brian Excel Worksheet Functions 4 December 15th 04 08:59 PM
Zip Code Macro Ken Wright Excel Worksheet Functions 0 December 9th 04 07:55 AM


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