Display Title Row Heading based on Active cell

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
833
Hi All

I am looking for a bit of VB code to add to a project. The purpose is to display the Title Row Heading based on the Active Cell in a text box on my userform.

Example:

On a spreadsheet, Range ("F1:AS1") has the following titles; Q1, Q2, Q3 etc up to Q40. If the user selects cell F2 then Q1 would be displayed in the textbox. If J19 is selected the Q5 would be displayed. If a cell outside the range ("F:AS") is selected then the textbox should be blank.

Any help with some VB would be greatly appreciated.

Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
How about?

Code:
Private Sub UserForm_Initialize()
    With ActiveCell
        If .Column < 6 Or .Column > 45 Then
            TextBox1.Text = ""
        Else
            TextBox1.Text = .EntireColumn.Cells(1, 1).Value
        End If
    End With
End Sub
 
Upvote 0
Hi
paste the following codes in the macro window ( alt F11)

Code:
a = activecell.row
b = activecell.column
textbox1.text = cells(1,b-5).value ' or "Q" & b-5
Run the macro
ravi
 
Upvote 0
Hi Andrew and ravishankar

Thanks for the quick replies, problem sorted. :biggrin:
 
Upvote 0

Forum statistics

Threads
1,214,724
Messages
6,121,149
Members
449,012
Latest member
LuBurt

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