Multiple non-contiguous cells selection in same column

YaYa08

New Member
Joined
Oct 22, 2015
Messages
30
Help please.
I need to go to the end of a column and highlight the cell in the forth and fifth row and then only the cell in row 21 of the same column.

Please advise how to write VBA for this. My End Right column changes weekly

Currently I have:

Range("C4").End(xlToRight).Offset(-1, -1).Select (which is the first cell)
I need to include the next cell in row below and the last cell in column which is row 21.
 
Okay, if I understand correctly, Column DB is your last column and you want to select the cells on Rows 4, 5 and 21 for that column. If that is correct, this line of code will do that...

Range("DB4:DB5,DB21").Select
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Rick thanks but I already knew that. But the last columns changes as I run the report weekly.
What I am trying to get at is to:
identify the last column
then select cells 4, 5, & 21 in the last column.

Currently it is DB, but next week it will be something beyond DB.

Last column is variable and cells 4,5,&21 are static

I hope that makes sense.
 
Upvote 0
Okay, then give this line of code a try...
VBA Code:
Intersect(Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).EntireColumn, Range("4:5,21:21")).Select
 
Upvote 0
So far looks like it will work. I'll confirm when I run the report on Monday.

Thank you so much. Was it as complicated to come up with the correct code as I thought it was?

Can you please break down the code and explain it to me. I understand that last part but not this part:

ls.Find("*", , xlValues, , xlByColumns, xlPrevious)

Why use 2 (commas) inbetween some criteria and not for others?
 
Upvote 0
The double comma means the argument at that would occur between them is not being specified, hence the default value (or the current value if that is a remembered argument) will be used... the reason nothing is specified is because no matter what the setting is, it would have no bearing on the search being performed.
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,974
Members
448,537
Latest member
Et_Cetera

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