Selecting a table row in a table using VBA

bearcub

Well-known Member
Joined
May 18, 2005
Messages
731
Office Version
  1. 365
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
Hi,

If I have a table and I want to highlight the table row (ala conditional formatting a row in a table) -- how would I do that?

I original thought of using the current range property but that will select the entire table not active table row where I have my cursor.

My first thought is to do something like this:

Range(Activecell.end(xlRight), Activecell.end(xlLeft). select

However, I don't think this would really work in VBA and there is probably a more efficient and correct what of doing this.

What am I doing wrong?

Michael
 
Thank you for the answers.

Yes, the column is doing to be dynamic because the column location will not always be the same. Sometimes the cell might be in Column C or Column D or Column A. I like the highlight only the row that has data in it, not the empty cells that are to the left or right of the data.

Michael
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I like the highlight only the row that has data in it, not the empty cells that are to the left or right of the data

What is wrong with the code Rick posted in post #7?
 
Last edited:
Upvote 0
Sorry, didn't mean to come off like that. It actually worked great and I thought it was cool the way he used Intersect method.

All code snippets worked and I was really in awe of the different ways to arrive at the same conclusion.

Thank you all for you help!

Michael
 
Upvote 0
I like the highlight only the row that has data in it, not the empty cells that are to the left or right of the data
All code snippets worked


The code I posted in post #9 doesn't work for the condition in bold. It always starts in column A.
To match the condition it would need to be...

Code:
Sub xxx()
    If Cells(ActiveCell.Row, 1) <> "" Then
        Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, Columns.Count).End(xlToLeft)).Select
    Else
        Range(Cells(ActiveCell.Row, 1).End(xlToRight), Cells(ActiveCell.Row, Columns.Count).End(xlToLeft)).Select
    End If
End Sub
 
Upvote 0
Ah, I see that I didn't reread what I wrote. There was a typo in that sentence. I didn't mean to say "like the highlight" I meant to say "want to highlight". Apologize for the confusion.

I did try your original code and the newest one and they seem to work okay either way. Thank you for taking the time to provide the correction.

Michael
 
Upvote 0

Forum statistics

Threads
1,222,617
Messages
6,167,074
Members
452,094
Latest member
Roberto Saveru

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