Search for the column that contains a given text, and then search for the row that contains the last non-blank cell in the worksheet

sneakymist

New Member
Joined
Jan 16, 2018
Messages
3
I am trying to create a code that does two things:

  1. First, the code will search for a column that contains a given text within the worksheet.
  2. Afterwards, the code will search for the row with the last non-blank cell in the worksheet, while remaining on the same column as 1.

    SzZ6A.png



    As shown in the example above, the code would first search for the text "FIRST" in A1. Afterwards, it will search for the last non-blank cell in the worksheet, which is C11. However, it should remain in the column that contains "FIRST", so that only the row changes. The final result would be A11.
    So far, I found the code that lets me do 1.

    Code:
      [CODE]Cells.Find(what:="FIRST", 
                   after:=ActiveCell, 
                   LookIn:=xlFormulas, 
                   LookAt:=xlPart, 
                   SearchOrder:=xlByRows, 
                   SearchDirection:=xlNext, 
                   MatchCase:=False, 
                   SearchFormat:=False).Activate

    and another code that lets me do 2.,

    Cells.Find(what:="*",
    after:=Range("A1"),
    LookAt:=xlPart,
    LookIn:=xlFormulas,
    SearchOrder:=xlByRows,
    SearchDirection:=xlPrevious,
    MatchCase:=False).Activate
    [/CODE]

    However, I am unable to use them together to achieve my intended goal.


    Any suggestions to answer this would be appreciated. Thank you!


 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
When you say "the final result would be A11", did you mean that cell A11 would be selected? If so...
Code:
[table="width: 500"]
[tr]
	[td]Intersect(Cells.Find("FIRST", ActiveCell, xlFormulas, xlPart, xlByRows, xlNext, False, False).EntireColumn, Cells.Find(what:="*", after:=Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).EntireRow).Select[/td]
[/tr]
[/table]
 
Upvote 0
When you say "the final result would be A11", did you mean that cell A11 would be selected? If so...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Intersect(Cells.Find("FIRST", ActiveCell, xlFormulas, xlPart, xlByRows, xlNext, False, False).EntireColumn, Cells.Find(what:="*", after:=Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).EntireRow).Select[/TD]
[/TR]
</tbody>[/TABLE]

Yes, that is what I meant.

Just tested what you wrote, works great!

Thank you for the reply, really appreciate it!
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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