Find text, select row and define selected row

nafanya

Board Regular
Joined
Sep 19, 2008
Messages
63
Hi, i'm looking for macro that would find text select that row and define a name for that row, for example find text "hello" select that row and define the name for that row "hello". i got to the point where it finds the name and selects that row - how can i define the selected row?

thank you

here is the code i got so far

Application.CommandBars("Stop Recording").Visible = False
Cells.Find(What:="hello", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).EntireRow.Select
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Welcome to the Board!

How 'bout something like this:

<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> foo()<br>    <SPAN style="color:#00007F">Dim</SPAN> ans <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> NewRange <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <br>    ans = InputBox("Enter search term", "Search for?")<br>    <br>    NewRange = Cells.Find(What:=ans, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _<br>        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _<br>        , SearchFormat:=False).EntireRow.Address<br>        <br>        ActiveWorkbook.Names.Add Name:=ans, RefersToR1C1:=NewRange<br>        <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Hope that helps,
 
Upvote 0
No need to select
Code:
Sub Fanugi()
Cells.Find(What:="hello", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).EntireRow.Name = "hello"
End Sub

lenze
just noticed Smitty's take on this. Using his idea, maybe
Code:
Dim myWord As String
myWord = InputBox("enter word")
Cells.Find(What:=myWord, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).EntireRow.Name = myWord
End Sub

lenze
 
Last edited:
Upvote 0
i have one more question - is it possilbe to create a macro that would copy info from cell a1 and name the row with that info, also loop it to do it from row 1 to 3000 (of course to take the info from cell a2 and name the row 2 with that info and so on until reaches row 3000)

again thank you very much for your help
 
Upvote 0
I can't think if why you would want 3000 defined names, but here's a shot:

<font face=Tahoma><SPAN style="color:#00007F">Sub</SPAN> foo()<br>    <SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>        <SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> 3000<br>            Cells(i, "A").EntireRow.Name = Cells(i, "A").Text<br>        <SPAN style="color:#00007F">Next</SPAN> i<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Note that there's no test for valid range names or duplicates.
 
Upvote 0
Hi, Smitty - thank you for your answer - i got very similar thing - while using it i found a problem - the names that i use most of the time has at least 2 words and excel doesn't allow to use spaces in defining row names so in macro it's asking to replace spaces with _ (underscore) i was wondering if beside replacing spaces you can add "-" character as well - pretty much look for space or - and replace it with _ (underscore) thank you - here is the code:

Sub Macro1()
Dim a As Long
For a = 1 To Cells(Rows.Count, 1).End(xlUp).Row
Cells(a, 26) = Application.WorksheetFunction.Substitute(Cells(a, 1), " ", "_")
ActiveWorkbook.Names.Add Name:=Cells(a, 26), RefersToR1C1:="=Sheet1!R" & a
Next a
End Sub

again thank you very much for your help
 
Upvote 0
actually if it's possilbe to replace all special characters to _ (underscore) if not then just those 2.

thank you
 
Upvote 0

Forum statistics

Threads
1,215,092
Messages
6,123,063
Members
449,090
Latest member
fragment

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top