Macro to select rows in column of activecell

floridagunner

Board Regular
Joined
Jul 20, 2007
Messages
60
Hello I need help with a macro to select all the rows in the column of the active cell.

The number of rows that are selected are based on the number of rows with data in column A.

However I'm getting an error when I use the code below:

Code:
Sub SelectColumn()

Dim CC As Long
myfield1 = ActiveCell.Column

CC = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Offset(-1, 0).Row

Range(Column, Cells(lr, myfield1)).Select

End Sub

Can anyone help me in correcting this code ?

Thanks









End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
lr is null, and you can't have a null row.


Code:
[COLOR=#333333]Range(Column, Cells(lr, myfield1)).Select[/COLOR]
 
Upvote 0
Does anybody know how I can fix this code. I need to select all rows in the column of the activecell based on the number of populated rows in Column A
 
Upvote 0
Does anybody know how I can fix this code. I need to select all rows in the column of the activecell based on the number of populated rows in Column A


Code:
Sub SelectColumn()
    Range(Cells(1, ActiveCell.Column), Cells(Range("A" & Rows.Count).End(xlUp).Row, ActiveCell.Column)).Select
End Sub

What I meant was, you were using "Column" and "LR" as undefined variables.
 
Upvote 0
Code:
Sub SelectColumn()
    Range(Cells(1, ActiveCell.Column), Cells(Range("A" & Rows.Count).End(xlUp).Row, ActiveCell.Column)).Select
End Sub

What I meant was, you were using "Column" and "LR" as undefined variables.

Thanks for your help NeonRed, your code worked ! :)
 
Upvote 0
Floridagunner,

try-

Code:
Sub SelectColumn()
Dim lr As Long
Dim myfield1 As Long
myfield1 = ActiveCell.Column

Sheets("Sheet1").Activate
lr = Worksheets("sheet1").Cells(Rows.Count, myfield1).End(xlUp).Row
Range(Cells(1, myfield1), Cells(lr, myfield1)).Select
End Sub

RE: Null-Noenredsharpie was referring to the fact that 'lr' was not picking up the last row. You were using CC to get your last row further, it was hard coded to only work on Col A not the active column you are looking for.

Hope this helps,

FarmerScott
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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