Link to home
Start Free TrialLog in
Avatar of jnikodym
jnikodym

asked on

Excel VBA - Need the value of cell in first row of selected cell

I need to create some vba code that will give me the first cell in the same column of any cell i select in a worksheet.  For example if i select cell A15, i need a variable that will result in cell A1.  If i select cell C555 i need it to give me cell C1.
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rgonzo1971
Rgonzo1971

Hi,

pls try
Msgbox Cells(1, Selection.Column).Value

Open in new window

Regards
Do you want to be able to just see row 1 no matter where you select in the column?

You can use Freeze Panes for that. This will create a split across the screen such that part of it does not move when scrolling.

Select A2 and then on the View menu select Freeze Panes. There are 3 options:
1) Freeze Panes - sets the pane boundaries at the point selected
2) Freeze top row - freezes row 1; this could the option you want
3) Freeze first column - freezes column A

This can actually be quite useful and can be used in other ways; see an article below which I wrote with other options.
 Freeze Panes
@Rob

I am surprised to see you posting in closed questions most of the times where you create your hypothetical assumptions and offer off topic suggestions.

What do you try to prove by doing this? Do you try to prove...

  • Askers don't explain their requirement well in the description? OR
  • You find that the Askers choose the wrong answers as accepted solutions? OR
  • You think you are mind reader and understand the question better than any other expert in the forum? OR
  • You don't understand what a closed question means?
None of the above and I am quite offended by your suggestion; I am not trying to prove anything.

Being a global forum EE attracts visitors from different time zones so there are occasions where a question could be raised and answered before visitors/experts from another time zone have a chance to look at it but may still have something valid to contribute. On that basis I regularly look at Closed questions to see if there is anything that I have missed where I could contribute or even learn from.

There are occasions where the description given in a question can be vague and open to interpretation, not necessarily in this case, so I have no qualms in offering an alternative solution even after a question solution has been accepted in case there has been some misunderstanding.

If EE did not want further comments after a question has been closed there would not be the option to do so or it would be limited to those that had already contributed so further discussion can occur on the chosen solution where follow up is required.