.Find text in coloumn and return row number

MadeleineB

New Member
Joined
Sep 23, 2008
Messages
18
First => I'm trying to return the row number of the first instant of the word "Day 1" in a column, looking down the column.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
Second => Once I have the row number I will then format the columns C:N in row ? with a top border.<o:p></o:p>

I have the second part done (see below), but I'm stuck on the first:

I was looking as using .Find or xlUp with .Address. Anything I try is not working.


'------------------------first---------------------------------------

myDay1row = Worksheets("Business").Range("C1:C106").Find(What:="Day 1", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).


'-----------------------second--------------------------------------

Worksheets("Business").Range("C" & myDay1row & ":N" & myDay1row).Select

With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
 

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)
Code:
With Worksheets("Buisness")
    myDay1row = .Range("C1:C106").Find(What:="Day 1", After:=.Range("C106"), LookIn:=xlValues, LookAt:=xlWhole, _
        SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Row
End With
 
Upvote 0
It works a treat. Thanks Mike. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
I will now test it out on multiple worksheets.<o:p></o:p>
 
Upvote 0
Hi Mike,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
It has an error when I try and run it over multipliable sheets. Each sheet lay out is the same they just have data for different teams.

Run-time error '1004': Select method of Range class failed

Sub Format()
Dim myDay1row As String
With Worksheets("Business")
myDay1row = .Range("C1:C106").Find(What:="Day 1", After:=.Range("C106"), LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Row
End With

Worksheets("Business").Range("C" & myDay1row & ":N" & myDay1row).Select

With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
'////////////////////////////////////
With Worksheets("Test")
myDay1row = .Range("C1:C106").Find(What:="Day 1", After:=.Range("C106"), LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Row
End With

Worksheets("Test").Range("C" & myDay1row & ":N" & myDay1row).Select

With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
'////////////////////////////////////

End Sub
 
Upvote 0
If these sheets are in different workbooks, the first With of the below code needs to be more fully qualified.
Code:
With Worksheets("Test")
    myDay1Row = 0
    myDay1row = .Range("C1:C106").Find(What:="Day 1", After:=.Range("C106"), LookIn:=xlValues, LookAt:=xlWhole, _
        SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Row
    If myDay1Row = 0 then
        MsgBox "not found"
    Else
        With .Rows(myDay1Row).Range("C1:N1").Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
    End If
End With
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,044
Members
449,063
Latest member
ak94

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