Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Select cell by value

Ok...
I'm writing a macro in which i know that none of the values created in
a worksheet will be the same (except for blank cells). What
code/command can I use to search for a specific value in the worksheet
and then select the cell that contains that value?

Thanks in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Select cell by value

You can use find something like this

dim rngFound as range

set rngfound = sheets("sheet1").Columns("A").Find(What:="Find This", _

LookIn:=xlFormulas, _

LookAt:=xlPart, _

MatchCase:=False)
if rngfound is nothing then
msgbox "Sorry... Not found"
else
rngfound.select
end if
--
HTH...

Jim Thomlinson


" wrote:

Ok...
I'm writing a macro in which i know that none of the values created in
a worksheet will be the same (except for blank cells). What
code/command can I use to search for a specific value in the worksheet
and then select the cell that contains that value?

Thanks in advance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Select cell by value

I'm fairly new with this....

Could you explain what the code is saying, and also, I want it to
search the whole sheet and not just one column.
Jim Thomlinson wrote:
You can use find something like this

dim rngFound as range

set rngfound = sheets("sheet1").Columns("A").Find(What:="Find This", _

LookIn:=xlFormulas, _

LookAt:=xlPart, _

MatchCase:=False)
if rngfound is nothing then
msgbox "Sorry... Not found"
else
rngfound.select
end if
--
HTH...

Jim Thomlinson


" wrote:

Ok...
I'm writing a macro in which i know that none of the values created in
a worksheet will be the same (except for blank cells). What
code/command can I use to search for a specific value in the worksheet
and then select the cell that contains that value?

Thanks in advance.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Select cell by value

Using the Recorder to find 15:

Sub Macro1()
Cells.Find(What:="15", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=False).Activate
End Sub
--
Gary's Student


" wrote:

Ok...
I'm writing a macro in which i know that none of the values created in
a worksheet will be the same (except for blank cells). What
code/command can I use to search for a specific value in the worksheet
and then select the cell that contains that value?

Thanks in advance.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Select cell by value

This code is using the find function (same find as you use in an Excel
worksheet). The issue with using find in code is that it crashes if it does
not find something... For that reason I have a range object (rngfound) that I
set to the cell that is found (or not found). If the cell is not found then
the range object references nothing. So my if statement say if rngfound is
nothing then nothing was found. Else it selects the cell that was found...
Give this code a try. It looks at the entire active sheet.

Sub findStuff()
Dim rngFound As Range

Set rngFound = Cells.Find(What:="Find This", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry... Not found"
Else
rngFound.Select
End If
End Sub
--
HTH...

Jim Thomlinson


" wrote:

I'm fairly new with this....

Could you explain what the code is saying, and also, I want it to
search the whole sheet and not just one column.
Jim Thomlinson wrote:
You can use find something like this

dim rngFound as range

set rngfound = sheets("sheet1").Columns("A").Find(What:="Find This", _

LookIn:=xlFormulas, _

LookAt:=xlPart, _

MatchCase:=False)
if rngfound is nothing then
msgbox "Sorry... Not found"
else
rngfound.select
end if
--
HTH...

Jim Thomlinson


" wrote:

Ok...
I'm writing a macro in which i know that none of the values created in
a worksheet will be the same (except for blank cells). What
code/command can I use to search for a specific value in the worksheet
and then select the cell that contains that value?

Thanks in advance.






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Select cell by value

Great...thanks, one more thing, once I have a cell selected is there a
way to find out what cell is selected, as in "Sheet1.Cells(x, y)" and
if i have for example "Cells(2, 4)" is there a way to have it assign
those values to variables so that for example x = 2 and y = 4?

Thank you so much for the find code...it's a great help.
Jim Thomlinson wrote:
This code is using the find function (same find as you use in an Excel
worksheet). The issue with using find in code is that it crashes if it does
not find something... For that reason I have a range object (rngfound) that I
set to the cell that is found (or not found). If the cell is not found then
the range object references nothing. So my if statement say if rngfound is
nothing then nothing was found. Else it selects the cell that was found...
Give this code a try. It looks at the entire active sheet.

Sub findStuff()
Dim rngFound As Range

Set rngFound = Cells.Find(What:="Find This", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry... Not found"
Else
rngFound.Select
End If
End Sub
--
HTH...

Jim Thomlinson


" wrote:

I'm fairly new with this....

Could you explain what the code is saying, and also, I want it to
search the whole sheet and not just one column.
Jim Thomlinson wrote:
You can use find something like this

dim rngFound as range

set rngfound = sheets("sheet1").Columns("A").Find(What:="Find This", _

LookIn:=xlFormulas, _

LookAt:=xlPart, _

MatchCase:=False)
if rngfound is nothing then
msgbox "Sorry... Not found"
else
rngfound.select
end if
--
HTH...

Jim Thomlinson


" wrote:

Ok...
I'm writing a macro in which i know that none of the values created in
a worksheet will be the same (except for blank cells). What
code/command can I use to search for a specific value in the worksheet
and then select the cell that contains that value?

Thanks in advance.





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Select cell by value

rngFound is the found Cell so there are any number of things you can do...
Give this a quick try to see what I mean...

Sub findStuff()
Dim rngFound As Range
dim x as long
dim y as integer

Set rngFound = Cells.Find(What:="Find This", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry... Not found"
Else
rngFound.Select
msgbox rngFound.address
x= rngfound.row
y = rngfound.column
msgbox x & vbcrlf & y
msgbox "Value of next cell over is " & rngFound.offset(0, 1).value
set rngfound = rngfound.offset(1,0)
rngfound.select
End If
End Sub

--
HTH...

Jim Thomlinson


" wrote:

Great...thanks, one more thing, once I have a cell selected is there a
way to find out what cell is selected, as in "Sheet1.Cells(x, y)" and
if i have for example "Cells(2, 4)" is there a way to have it assign
those values to variables so that for example x = 2 and y = 4?

Thank you so much for the find code...it's a great help.
Jim Thomlinson wrote:
This code is using the find function (same find as you use in an Excel
worksheet). The issue with using find in code is that it crashes if it does
not find something... For that reason I have a range object (rngfound) that I
set to the cell that is found (or not found). If the cell is not found then
the range object references nothing. So my if statement say if rngfound is
nothing then nothing was found. Else it selects the cell that was found...
Give this code a try. It looks at the entire active sheet.

Sub findStuff()
Dim rngFound As Range

Set rngFound = Cells.Find(What:="Find This", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry... Not found"
Else
rngFound.Select
End If
End Sub
--
HTH...

Jim Thomlinson


" wrote:

I'm fairly new with this....

Could you explain what the code is saying, and also, I want it to
search the whole sheet and not just one column.
Jim Thomlinson wrote:
You can use find something like this

dim rngFound as range

set rngfound = sheets("sheet1").Columns("A").Find(What:="Find This", _

LookIn:=xlFormulas, _

LookAt:=xlPart, _

MatchCase:=False)
if rngfound is nothing then
msgbox "Sorry... Not found"
else
rngfound.select
end if
--
HTH...

Jim Thomlinson


" wrote:

Ok...
I'm writing a macro in which i know that none of the values created in
a worksheet will be the same (except for blank cells). What
code/command can I use to search for a specific value in the worksheet
and then select the cell that contains that value?

Thanks in advance.






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Select cell by value

Great! This was a big help!
Jim Thomlinson wrote:
rngFound is the found Cell so there are any number of things you can do...
Give this a quick try to see what I mean...

Sub findStuff()
Dim rngFound As Range
dim x as long
dim y as integer

Set rngFound = Cells.Find(What:="Find This", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry... Not found"
Else
rngFound.Select
msgbox rngFound.address
x= rngfound.row
y = rngfound.column
msgbox x & vbcrlf & y
msgbox "Value of next cell over is " & rngFound.offset(0, 1).value
set rngfound = rngfound.offset(1,0)
rngfound.select
End If
End Sub

--
HTH...

Jim Thomlinson


" wrote:

Great...thanks, one more thing, once I have a cell selected is there a
way to find out what cell is selected, as in "Sheet1.Cells(x, y)" and
if i have for example "Cells(2, 4)" is there a way to have it assign
those values to variables so that for example x = 2 and y = 4?

Thank you so much for the find code...it's a great help.
Jim Thomlinson wrote:
This code is using the find function (same find as you use in an Excel
worksheet). The issue with using find in code is that it crashes if it does
not find something... For that reason I have a range object (rngfound) that I
set to the cell that is found (or not found). If the cell is not found then
the range object references nothing. So my if statement say if rngfound is
nothing then nothing was found. Else it selects the cell that was found...
Give this code a try. It looks at the entire active sheet.

Sub findStuff()
Dim rngFound As Range

Set rngFound = Cells.Find(What:="Find This", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry... Not found"
Else
rngFound.Select
End If
End Sub
--
HTH...

Jim Thomlinson


" wrote:

I'm fairly new with this....

Could you explain what the code is saying, and also, I want it to
search the whole sheet and not just one column.
Jim Thomlinson wrote:
You can use find something like this

dim rngFound as range

set rngfound = sheets("sheet1").Columns("A").Find(What:="Find This", _

LookIn:=xlFormulas, _

LookAt:=xlPart, _

MatchCase:=False)
if rngfound is nothing then
msgbox "Sorry... Not found"
else
rngfound.select
end if
--
HTH...

Jim Thomlinson


" wrote:

Ok...
I'm writing a macro in which i know that none of the values created in
a worksheet will be the same (except for blank cells). What
code/command can I use to search for a specific value in the worksheet
and then select the cell that contains that value?

Thanks in advance.







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
VBA: Column Select then Data Select then return to cell A1 James C[_2_] Excel Discussion (Misc queries) 3 February 1st 10 11:35 AM
Using formulas to select cells (Ex: Select every nth cell in a col Lakeview Photographic Services Excel Discussion (Misc queries) 2 March 15th 07 02:17 PM
How to point to (select) a cell to the left from a cell where I enter the = equal sign? Dmitry Excel Discussion (Misc queries) 4 June 30th 06 06:49 AM
Select cell, Copy it, Paste it, Return to Previous cell spydor Excel Discussion (Misc queries) 1 December 30th 05 01:29 PM
Select First Active Cell if the cell is in a pivot table Don Excel Programming 0 June 30th 04 01:53 PM


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