VBA - returning a column letter

Khazimula

New Member
Joined
Jul 15, 2005
Messages
30
I've got a conundrum that's I've been mulling over all night with no luck. I am hoping someone on here knows a solution.

I am trying to reference a set range of rows within the active column (which will of course differ depending on which cell is selected when the macro is run). I know I can return the column number using activecell.column, and I was thinking I could perhaps change this into a letter (prfereably not using a table in Excel) and then have this as part of a range. Something along the lines of:

Range(ActiveCell.Column & "2" & ":" & ActiveCell.Column & "11").Select

...but with activecell.column returned as a letter.

I'm not certain this is the best way of going about it. I'm also aware there is something called R1C1, but its not an area of VBA I am familiar with and the help file on it hasn't been that helpful.

Any ideas on this would be greatly appreciated. I have a feeling the solution is right under my nose, but at the moment my nose is too big to allow me to see it.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
If you want to select the column of the activecell then you could use:

Code:
Columns(ActiveCell.Column).Select


Regards

Richard
 
Upvote 0
A couple of ways of making up the range;

Code:
Dim myRange As Range

Set myRange = Range(Cells(ActiveCell.Row + 2, ActiveCell.Column), Cells(ActiveCell.Row + 11, ActiveCell.Column))
MsgBox (myRange.Address)
Or,
Code:
Dim myRange As Range

Set myRange = Range(ActiveCell.Offset(2, 0).Address, ActiveCell.Offset(11, 0).Address)
MsgBox (myRange.Address)
 
Upvote 0
Thanks for the response Parsnip. Its got me thinking, but its not exactly what I'm trying to do. I don't want to select the entire column, just the part of the column that lies between two fixed row numbers (rows 2:11). If I could select the column and then within the column select the range between these two rows then that would work...
 
Upvote 0
Brilliant Fat Cat. Both methods should work with a bit of tweaking. I particularly like your first solution!

Thanks very much to you all :-D
 
Upvote 0
Hi,

This UDF returns the column letter of the column supplied:
Code:
Function GetCol(ByVal ColRqd As Integer) As String
Dim sCol As String
sCol = Cells(1, ColRqd).Address(True, False)
GetCol = Left$(sCol, InStr(sCol, "$") - 1)
End Function
 
Upvote 0
If the cells you want are a range of 10 cells always Offset by 2 from the active cell just use the Offset function

If your ActiveCell.Address is $H$19, then

ActiveCell.Offset(2,0).Address = $H$21
ActiveCell.Offset(11,0).Address = $H$30

Range(ActiveCell.Offset(2,0).Address , ActiveCell.Offset(11,0).Address).Address = $H$21:$H$30
 
Upvote 0

Forum statistics

Threads
1,224,427
Messages
6,178,587
Members
452,860
Latest member
jroberts02

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