Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Macro to run based on drop down list

I have a vlookup formula doing a different calculation depending of the value
in a drop down list. The format of the result of the calculation shall be
either a number or a percentage depending on the value of the same drop down
list. I see two options, either a macro that runs automatically when I change
the drop down list and that updates the format of my cells or a formula that
converts the format from number to percentage.
How do I run a macro based on a change in a drop down list?
Is there any formula to convert the format from number to percentage?

Thanks a lot!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Macro to run based on drop down list

Define Drop down list?
Combo Box from Control Toolbox? Combo Box from Forms Toolbar? Data
Validation List?
--
HTH...

Jim Thomlinson


"Bonobo" wrote:

I have a vlookup formula doing a different calculation depending of the value
in a drop down list. The format of the result of the calculation shall be
either a number or a percentage depending on the value of the same drop down
list. I see two options, either a macro that runs automatically when I change
the drop down list and that updates the format of my cells or a formula that
converts the format from number to percentage.
How do I run a macro based on a change in a drop down list?
Is there any formula to convert the format from number to percentage?

Thanks a lot!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macro to run based on drop down list

There's no formula that will change the numberformat of any cell.

But depending on what you used to create the dropdown, you may be able to use a
linked cell and use that in a formula that will "adjust" the original number.

Say A1 is your linked cell and it can be Pct (or something else).
And A2 is your cell with the number.
You could put this in A3:

=if(a1="pct",a2/100,a2)
or
=a2/(if(a1="pct",100,1)

You may be able to embed that same kind of formula into any existing formula--or
just adjust any existing formula to point at that 3rd cell.



Bonobo wrote:

I have a vlookup formula doing a different calculation depending of the value
in a drop down list. The format of the result of the calculation shall be
either a number or a percentage depending on the value of the same drop down
list. I see two options, either a macro that runs automatically when I change
the drop down list and that updates the format of my cells or a formula that
converts the format from number to percentage.
How do I run a macro based on a change in a drop down list?
Is there any formula to convert the format from number to percentage?

Thanks a lot!


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Macro to run based on drop down list

Thank you Dave, but this will not show the result as percentage... ie with
the % sign. what about running a macro whenever I change the selection in the
drop down list, any idea?

"Dave Peterson" wrote:

There's no formula that will change the numberformat of any cell.

But depending on what you used to create the dropdown, you may be able to use a
linked cell and use that in a formula that will "adjust" the original number.

Say A1 is your linked cell and it can be Pct (or something else).
And A2 is your cell with the number.
You could put this in A3:

=if(a1="pct",a2/100,a2)
or
=a2/(if(a1="pct",100,1)

You may be able to embed that same kind of formula into any existing formula--or
just adjust any existing formula to point at that 3rd cell.



Bonobo wrote:

I have a vlookup formula doing a different calculation depending of the value
in a drop down list. The format of the result of the calculation shall be
either a number or a percentage depending on the value of the same drop down
list. I see two options, either a macro that runs automatically when I change
the drop down list and that updates the format of my cells or a formula that
converts the format from number to percentage.
How do I run a macro based on a change in a drop down list?
Is there any formula to convert the format from number to percentage?

Thanks a lot!


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macro to run based on drop down list

The code would depend on the type of dropdown you used.

Did you use a combobox from the control toolbox toolbar?
Did you use a dropdown from the Forms toolbar?
Did you use data|validation (and what version of excel do you use?)

Bonobo wrote:

Thank you Dave, but this will not show the result as percentage... ie with
the % sign. what about running a macro whenever I change the selection in the
drop down list, any idea?

"Dave Peterson" wrote:

There's no formula that will change the numberformat of any cell.

But depending on what you used to create the dropdown, you may be able to use a
linked cell and use that in a formula that will "adjust" the original number.

Say A1 is your linked cell and it can be Pct (or something else).
And A2 is your cell with the number.
You could put this in A3:

=if(a1="pct",a2/100,a2)
or
=a2/(if(a1="pct",100,1)

You may be able to embed that same kind of formula into any existing formula--or
just adjust any existing formula to point at that 3rd cell.



Bonobo wrote:

I have a vlookup formula doing a different calculation depending of the value
in a drop down list. The format of the result of the calculation shall be
either a number or a percentage depending on the value of the same drop down
list. I see two options, either a macro that runs automatically when I change
the drop down list and that updates the format of my cells or a formula that
converts the format from number to percentage.
How do I run a macro based on a change in a drop down list?
Is there any formula to convert the format from number to percentage?

Thanks a lot!


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Macro to run based on drop down list

I am using data validation in Excel 2003

"Dave Peterson" wrote:

The code would depend on the type of dropdown you used.

Did you use a combobox from the control toolbox toolbar?
Did you use a dropdown from the Forms toolbar?
Did you use data|validation (and what version of excel do you use?)

Bonobo wrote:

Thank you Dave, but this will not show the result as percentage... ie with
the % sign. what about running a macro whenever I change the selection in the
drop down list, any idea?

"Dave Peterson" wrote:

There's no formula that will change the numberformat of any cell.

But depending on what you used to create the dropdown, you may be able to use a
linked cell and use that in a formula that will "adjust" the original number.

Say A1 is your linked cell and it can be Pct (or something else).
And A2 is your cell with the number.
You could put this in A3:

=if(a1="pct",a2/100,a2)
or
=a2/(if(a1="pct",100,1)

You may be able to embed that same kind of formula into any existing formula--or
just adjust any existing formula to point at that 3rd cell.



Bonobo wrote:

I have a vlookup formula doing a different calculation depending of the value
in a drop down list. The format of the result of the calculation shall be
either a number or a percentage depending on the value of the same drop down
list. I see two options, either a macro that runs automatically when I change
the drop down list and that updates the format of my cells or a formula that
converts the format from number to percentage.
How do I run a macro based on a change in a drop down list?
Is there any formula to convert the format from number to percentage?

Thanks a lot!

--

Dave Peterson


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Macro to run based on drop down list

I managed to get what I want with the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
If Range("A4") = "%" Then
Range("C4:D5").Select
Selection.Style = "Percent"
End If
If Range("A4") = "#" Then
Range("C4:D5").Select
Selection.NumberFormat = "#,##0.00"
End If
End If
End Sub

Thanks anyway!

"Dave Peterson" wrote:

The code would depend on the type of dropdown you used.

Did you use a combobox from the control toolbox toolbar?
Did you use a dropdown from the Forms toolbar?
Did you use data|validation (and what version of excel do you use?)

Bonobo wrote:

Thank you Dave, but this will not show the result as percentage... ie with
the % sign. what about running a macro whenever I change the selection in the
drop down list, any idea?

"Dave Peterson" wrote:

There's no formula that will change the numberformat of any cell.

But depending on what you used to create the dropdown, you may be able to use a
linked cell and use that in a formula that will "adjust" the original number.

Say A1 is your linked cell and it can be Pct (or something else).
And A2 is your cell with the number.
You could put this in A3:

=if(a1="pct",a2/100,a2)
or
=a2/(if(a1="pct",100,1)

You may be able to embed that same kind of formula into any existing formula--or
just adjust any existing formula to point at that 3rd cell.



Bonobo wrote:

I have a vlookup formula doing a different calculation depending of the value
in a drop down list. The format of the result of the calculation shall be
either a number or a percentage depending on the value of the same drop down
list. I see two options, either a macro that runs automatically when I change
the drop down list and that updates the format of my cells or a formula that
converts the format from number to percentage.
How do I run a macro based on a change in a drop down list?
Is there any formula to convert the format from number to percentage?

Thanks a lot!

--

Dave Peterson


--

Dave Peterson

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macro to run based on drop down list

If you want to try, rightclick on the worksheet tab that has the
data|validation. Select view code and paste this in the codewindow:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myOtherCell As Range
Set myOtherCell = Me.Range("c3")

With Target
If .Cells.Count 1 Then Exit Sub
If Intersect(.Cells, Me.Range("a1")) Is Nothing Then Exit Sub

If LCase(.Value) = "pct" Then
myOtherCell.NumberFormat = "0.00%"
Else
myOtherCell.NumberFormat = "0.00"
End If
End With

End Sub

I used A1 as the cell with data|validation and changed the format for cell C3.
Change to what you need.



Bonobo wrote:

I am using data validation in Excel 2003

"Dave Peterson" wrote:

The code would depend on the type of dropdown you used.

Did you use a combobox from the control toolbox toolbar?
Did you use a dropdown from the Forms toolbar?
Did you use data|validation (and what version of excel do you use?)

Bonobo wrote:

Thank you Dave, but this will not show the result as percentage... ie with
the % sign. what about running a macro whenever I change the selection in the
drop down list, any idea?

"Dave Peterson" wrote:

There's no formula that will change the numberformat of any cell.

But depending on what you used to create the dropdown, you may be able to use a
linked cell and use that in a formula that will "adjust" the original number.

Say A1 is your linked cell and it can be Pct (or something else).
And A2 is your cell with the number.
You could put this in A3:

=if(a1="pct",a2/100,a2)
or
=a2/(if(a1="pct",100,1)

You may be able to embed that same kind of formula into any existing formula--or
just adjust any existing formula to point at that 3rd cell.



Bonobo wrote:

I have a vlookup formula doing a different calculation depending of the value
in a drop down list. The format of the result of the calculation shall be
either a number or a percentage depending on the value of the same drop down
list. I see two options, either a macro that runs automatically when I change
the drop down list and that updates the format of my cells or a formula that
converts the format from number to percentage.
How do I run a macro based on a change in a drop down list?
Is there any formula to convert the format from number to percentage?

Thanks a lot!

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array Substitution Based on Drop Down List Royce Edwards Excel Discussion (Misc queries) 1 December 26th 09 09:13 PM
drop down list based on other drop down list pick Ruth Excel Discussion (Misc queries) 1 August 25th 09 04:12 PM
Drop down list based on choice of another dropdown Amy Excel Discussion (Misc queries) 2 January 23rd 08 08:39 PM
count based on selection from drop down list lovejunkie02 Excel Worksheet Functions 2 September 21st 07 10:04 PM
Update Formula's based on drop down list value Steven Taylor Excel Worksheet Functions 3 July 15th 07 01:48 AM


All times are GMT +1. The time now is 05:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"