VBA defined name help

jdmetcalfe

New Member
Joined
Dec 8, 2012
Messages
8
Hi i'm pretty new to vba and having real trouble with what should be a simple code.

I have the following vba code which works fine

Sub printlist()


If UCase(Range("T6").Value) = "1" Then Call stocksheetsub
If UCase(Range("T6").Value) = "2" Then Call supplier2sub




End Sub

However instead of using the cell value T6 i would like to replace this with a defined name so

Sub printlist()


If UCase(Range("reportlist").Value) = "1" Then Call stocksheetsub
If UCase(Range("reportlist").Value) = "2" Then Call supplier2sub




End Sub

Everything i try i just get errors. Any help would be much apreciated.

Thanks

James
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Maybe all you need is
If UCase("reportlist").Value = "1" Then Call stocksheetsub
and so on

But on another topic, I cannot recall seeing UCASE be invoked when a number is being evaluated as the potential value. I'm not so sure you need to evaluate an integer's case as you would an alphabet letter, nor might you need to place the number in quotes, unless it's being regarded as text somehow.
 
Upvote 0
What error(s) do you get? Is "reportlist" defined by a formula (e.g. a dynamic range) or is it a hard-coded range e.g.refersTo=$T$6)? Does "reportlist" have a workbook-level or sheet-level scope?
 
Upvote 0
okay thanks all i need to do is call a macro based on the number in a cell defined by the name report list

I'm not sure the best way to do this but basically

IF T6 = 1 run macro 1
IF T6 = 2 run macro 2
If T6 =3 run macro 3

Thats all i found that other code on forum and it seemed to work
 
Upvote 0
Just using the cell itself as an example:

Select Case Range("T6").Value
case 1: Run "stocksheetsub"
case 2: Run "supplier2sub"
case 3: Run "whatever3sub"
End Select
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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