Userform title based on a cell value

MrOzman

New Member
Joined
May 16, 2007
Messages
49
I don't understand why this isn't working.

Sub showsheet()
UserForm1.Caption = Range("Adm!b2").Value
UserForm1.Show
UserForm1.TextBox1.SetFocus
End Sub

I need the titlebar of the userform to show whatever is in Adm!b2. If it's important this value will always be text.

Thanks in advance.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
That should work as long as the code is in a normal module.
 
Upvote 0
Thanks for that.

I had it in the code for sheet 1.

Is there a short explanation that a simpleton would understand for why having it in a module makes a difference?
 
Upvote 0
Yep - when you use:
Code:
Range("Adm!b2").Value
in the worksheet code module for Sheet1, what it translates to is:
Code:
Sheet1.Range("Adm!b2").Value
which doesn't make sense since the range is not on Sheet1. In a normal module, it translates to:
Code:
Application.Range("Adm!b2").Value
which is OK. I would use:
Code:
Worksheets("Adm").Range("b2").Value
or even:
Code:
ThisWorkbook.Worksheets("Adm").Range("b2").Value
which will work pretty much anywhere.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

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