Display Title Row Heading based on Active cell

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
807
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
 

Some videos you may like

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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
 

ravishankar

Well-known Member
Joined
Feb 23, 2006
Messages
3,566
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
 

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
807
Hi Andrew and ravishankar

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

Watch MrExcel Video

Forum statistics

Threads
1,123,481
Messages
5,601,918
Members
414,482
Latest member
morkar

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
Top