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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
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,918
Messages
6,122,246
Members
449,075
Latest member
staticfluids

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