.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
 

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,614
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
 

MadeleineB

New Member
Joined
Sep 23, 2008
Messages
18
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>
 

MadeleineB

New Member
Joined
Sep 23, 2008
Messages
18
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
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,614
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
 

Watch MrExcel Video

Forum statistics

Threads
1,101,809
Messages
5,483,037
Members
407,374
Latest member
davidausten

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top