Select no-empty data from a column - VBA.

Franxja

New Member
Joined
Jul 19, 2018
Messages
3
Hi everyone, I have a question with VBA, if anyone could help me, I would be very grateful. I think it's a pretty noobie question :LOL:


I need, from a selected column, to select those items that contain data. I hope it will be better understood with the following image:

kd1cEJ

kd1cEJ

https://ibb.co/kd1cEJ

Using the macro recorder, I got the following code, which for some reason does not work.


Sub example()

Range(Selection, Selection.End(xlUp)).Select

End Sub

Thanks.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I forgot to say that will never be null cells between the first and the last cell with data in the column.
 
Upvote 0
Try this

Code:
Sub example()
Range("D1:D" & Cells(Rows.Count, 4).End(xlUp).Row).Select
End Sub
 
Upvote 0
Try this

Code:
Sub example()
Range("D1:D" & Cells(Rows.Count, 4).End(xlUp).Row).Select
End Sub


It worked perfect, thanks you very much!
I have a last question, how to make it work whatever column is selected?
****** id="cke_pastebin" style="position: absolute; top: 0px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">it worked perfect, thank you very much</body>
 
Upvote 0
Maybe this...but the code must be pasted in the worksheet module !!

Code:
Private Sub worksheet_selectionchange(ByVal target As Range)
Application.EnableEvents = False
Selection.End(xlUp).Select
Range(Selection, Selection.End(xlDown)).Select
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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