I was creating the following procedures. I want to give it class like structure.
I will provide name of a range or table as argument. Then I need to use the procedure in other vba like below:
This should return the expected address for MyRange.
How should I do this?
Code:
Sub SelectionRegionAddress(ByVal SelectionName As Range)
Dim Region_Address As String
Dim TopLeft_Address As String
Dim TopLeft_RowNum As Long
Dim TopLeft_ColumnNum As Long
'Dim TopLeft_RowLetter As String
Dim TopLeft_ColumnLetter As String
Dim TopRight_Address As String
Dim TopRight_RowNum As Long
Dim TopRight_ColumnNum As Long
'Dim TopRight_RowLetter As String
Dim TopRight_ColumnLetter As String
Dim BottomLeft_Address As String
Dim BottomLeft_RowNum As Long
Dim BottomLeft_ColumnNum As Long
'Dim BottomLeft_RowLetter As String
Dim BottomLeft_ColumnLetter As String
Dim BottomRight_Address As String
Dim BottomRight_RowNum As Long
Dim BottomRight_ColumnNum As Long
'Dim BottomRight_RowLetter As String
Dim BottomRight_ColumnLetter As String
Dim Region_Height As Long
Dim Region_Width As Long
Application.ScreenUpdating = False
Range("SelectionName").CurrentRegion.Select
Region_Address = Selection.Address
TopLeft_Address = Split(Region_Address, ":")(0) '//returns 1st part
'Left(Region_Address, InStr(Region_Address, ":") - 1)
TopLeft_ColumnLetter = Split(TopLeft_Address, "$")(1)
TopLeft_RowNum = Split(TopLeft_Address, "$")(2) 'Range(TopLeft_Address).Row
TopLeft_ColumnNum = Range(TopLeft_Address).Column
BottomRight_Address = Split(Region_Address, ":")(1) 'returns 2nd part
'Right(Region_Address, Len(Region_Address)-InStr(Region_Address, ":"))
BottomRight_ColumnLetter = Split(BottomRight_Address, "$")(1)
BottomRight_RowNum = Split(BottomRight_Address, "$")(2)
BottomRight_ColumnNum = Range(BottomRight_Address).Column
TopRight_Address = BottomRight_ColumnLetter & TopLeft_RowNum
TopRight_ColumnLetter = BottomRight_ColumnLetter
TopRight_RowNum = TopLeft_RowNum
TopRight_ColumnNum = Range(TopRight_Address).Column
BottomLeft_Address = TopLeft_ColumnLetter & BottomRight_RowNum
BottomLeft_ColumnLetter = TopLeft_ColumnLetter
BottomLeft_RowNum = BottomRight_RowNum
BottomLeft_ColumnNum = Range(BottomLeft_Address).Column
Region_Height = BottomLeft_RowNum - TopLeft_RowNum + 1 'including header row
Region_Width = TopRight_ColumnNum - TopLeft_ColumnNum + 1
Application.ScreenUpdating = True
End Sub
I will provide name of a range or table as argument. Then I need to use the procedure in other vba like below:
Code:
SelectionRegionAddress (MyRange).BottomLeft_RowNum
How should I do this?