?
Solved

Get the Extreme Left and Right Cell addresses

Posted on 2012-08-16
5
Medium Priority
?
456 Views
Last Modified: 2012-08-16
Hello Everyone,

I am looking for a code that does this. I am tired to manually mentioning the first and the last column header address in all of my functions so need this macro to grab these extreme left – right cell address. Now..
What it does >> it looks at sheet1  - the very first row that has the column names – searches left and right….when it searches left, it grabs c1’ cell address (B3)  - when it searches extreme right, it gets the c9’s cell address and finally give s a msgbox saying :
Left Header Cell : “B3”
Right Header Cell: “J3”

Please note that the first row that has the column names can be at row 3 or any other row…so it has to do some type of search or something
leftrightCells.xlsx
0
Comment
Question by:Rayne
5 Comments
 
LVL 24

Accepted Solution

by:
Steve earned 2000 total points
ID: 38299947
One way to do it:

Sub TopColumns()

Dim uRange As Range
Set uRange = ActiveSheet.UsedRange.Rows(1)

TopLeft = Replace(Left(uRange.Address, InStr(1, uRange.Address, ":", vbTextCompare) - 1), "$", "")
TopRight = Replace(Right(uRange.Address, Len(uRange.Address) - InStr(1, uRange.Address, ":", vbTextCompare)), "$", "")

MsgBox ("Left Header Cell : '" & TopLeft & "'" & vbCrLf & "Right Header Cell: '" & TopRight & "'")

End Sub

Open in new window

0
 
LVL 35

Expert Comment

by:Norie
ID: 38300043
Rayne

How can you tell which row is the row with headings?
0
 
LVL 8

Expert Comment

by:Elton Pascua
ID: 38300086
What are the extreme left and extreme right headings called? You said the row would vary but would the columns always be the same?
0
 

Author Comment

by:Rayne
ID: 38300722
Hello All,

For your excellent feedbacks: I will be opening a second question follow to this and get all other different approaches towards this issue.

The_Barman: Thank your solution works for me. you used used range. I would now want to see if there is nay other approach (s) different from this method.

 
imnorie: How can you tell which row is the row with headings?

The top most row is most likely to be the row with headings - now the top-most row could be on row3 or row 5 or any row

 


techfanatic
 What are the extreme left and extreme right headings called? You said the row would vary but would the columns always be the same?
C1, C9
Actually, the users would be adding in more columns at the end of the table, so the last column will change with time.


I have posted another question for you guys > if you can come up with different approaches to resolve this issue.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft has changed the look and feel of Azure AD and Microsoft account sign-in pages so that you will have a more unified look and feel when moving between the two interfaces.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question