ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Multiple cell formulas in different cells (https://www.excelbanter.com/excel-discussion-misc-queries/237788-multiple-cell-formulas-different-cells.html)

JulianP

Multiple cell formulas in different cells
 
I would like to use a pull down menu to control the formulas in different
cells. For example if the pulldown is set to A then the formula in cells
are one thing. If set to B then the formula in that cell would change to
something else. I have though of using if statements, but this gets messy.
Do I need to get in to macro writing? I am looking for something simple.
Cheers

Eduardo

Multiple cell formulas in different cells
 
Hi,
Could you be more specific, which are the formulas, a sample will help

"JulianP" wrote:

I would like to use a pull down menu to control the formulas in different
cells. For example if the pulldown is set to A then the formula in cells
are one thing. If set to B then the formula in that cell would change to
something else. I have though of using if statements, but this gets messy.
Do I need to get in to macro writing? I am looking for something simple.
Cheers


David Biddulph[_2_]

Multiple cell formulas in different cells
 
CHOOSE ?
LOOKUP ?
--
David Biddulph

"JulianP" wrote in message
...
I would like to use a pull down menu to control the formulas in different
cells. For example if the pulldown is set to A then the formula in cells
are one thing. If set to B then the formula in that cell would change to
something else. I have though of using if statements, but this gets
messy.
Do I need to get in to macro writing? I am looking for something simple.
Cheers




Gary''s Student

Multiple cell formulas in different cells
 
Say we have a Data Validation drop-down in A1 that selects from:
a,b,c,d
and we want to make the formula in A4:

=A1+A2
or
=A1-A2
or
=A1*A2
or
=A1/A2

Insert the following macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim a1 As Range, t As Range, v As String
Dim formu As String
Set a1 = Range("A1")
Set t = Target
If Intersect(a1, t) Is Nothing Then Exit Sub
v = t.Value
If v = "a" Then formu = "=A2+A3"
If v = "b" Then formu = "=A2-A3"
If v = "c" Then formu = "=A2*A3"
If v = "d" Then formu = "=A2/A3"
Application.EnableEvents = False
Range("A4").Formula = formu
Application.EnableEvents = True
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu200859


"JulianP" wrote:

I would like to use a pull down menu to control the formulas in different
cells. For example if the pulldown is set to A then the formula in cells
are one thing. If set to B then the formula in that cell would change to
something else. I have though of using if statements, but this gets messy.
Do I need to get in to macro writing? I am looking for something simple.
Cheers


Stefi

Multiple cell formulas in different cells
 
If number of options is limited, why not simply =IF(A1="X",formula1,formula2)
or =IF(A1="X",formula1,IF(A2="Y",formula2, ...)) etc.

Regards,
Stefi

€˛Gary''s Student€¯ ezt Ć*rta:

Say we have a Data Validation drop-down in A1 that selects from:
a,b,c,d
and we want to make the formula in A4:

=A1+A2
or
=A1-A2
or
=A1*A2
or
=A1/A2

Insert the following macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim a1 As Range, t As Range, v As String
Dim formu As String
Set a1 = Range("A1")
Set t = Target
If Intersect(a1, t) Is Nothing Then Exit Sub
v = t.Value
If v = "a" Then formu = "=A2+A3"
If v = "b" Then formu = "=A2-A3"
If v = "c" Then formu = "=A2*A3"
If v = "d" Then formu = "=A2/A3"
Application.EnableEvents = False
Range("A4").Formula = formu
Application.EnableEvents = True
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu200859


"JulianP" wrote:

I would like to use a pull down menu to control the formulas in different
cells. For example if the pulldown is set to A then the formula in cells
are one thing. If set to B then the formula in that cell would change to
something else. I have though of using if statements, but this gets messy.
Do I need to get in to macro writing? I am looking for something simple.
Cheers


Gary''s Student

Multiple cell formulas in different cells
 
The OP specifically asked for an alternative to IF statements.

I agree that your suggestion is the better solution.

Even if the number of options was very large, it would be better to store
all the formulas in a table and then use VLOOKUP()
--
Gary''s Student - gsnu200859


"Stefi" wrote:

If number of options is limited, why not simply =IF(A1="X",formula1,formula2)
or =IF(A1="X",formula1,IF(A2="Y",formula2, ...)) etc.

Regards,
Stefi

€˛Gary''s Student€¯ ezt Ć*rta:

Say we have a Data Validation drop-down in A1 that selects from:
a,b,c,d
and we want to make the formula in A4:

=A1+A2
or
=A1-A2
or
=A1*A2
or
=A1/A2

Insert the following macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim a1 As Range, t As Range, v As String
Dim formu As String
Set a1 = Range("A1")
Set t = Target
If Intersect(a1, t) Is Nothing Then Exit Sub
v = t.Value
If v = "a" Then formu = "=A2+A3"
If v = "b" Then formu = "=A2-A3"
If v = "c" Then formu = "=A2*A3"
If v = "d" Then formu = "=A2/A3"
Application.EnableEvents = False
Range("A4").Formula = formu
Application.EnableEvents = True
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu200859


"JulianP" wrote:

I would like to use a pull down menu to control the formulas in different
cells. For example if the pulldown is set to A then the formula in cells
are one thing. If set to B then the formula in that cell would change to
something else. I have though of using if statements, but this gets messy.
Do I need to get in to macro writing? I am looking for something simple.
Cheers


Stefi

Multiple cell formulas in different cells
 
Yes, I didn't notice that he wants a pulldown of formulae! Maybe he doesn't
know other techniques like embedded IFs, VLOOKUP, etc.

Regards,
Stefi

€˛Gary''s Student€¯ ezt Ć*rta:

The OP specifically asked for an alternative to IF statements.

I agree that your suggestion is the better solution.

Even if the number of options was very large, it would be better to store
all the formulas in a table and then use VLOOKUP()
--
Gary''s Student - gsnu200859


"Stefi" wrote:

If number of options is limited, why not simply =IF(A1="X",formula1,formula2)
or =IF(A1="X",formula1,IF(A2="Y",formula2, ...)) etc.

Regards,
Stefi

€˛Gary''s Student€¯ ezt Ć*rta:

Say we have a Data Validation drop-down in A1 that selects from:
a,b,c,d
and we want to make the formula in A4:

=A1+A2
or
=A1-A2
or
=A1*A2
or
=A1/A2

Insert the following macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim a1 As Range, t As Range, v As String
Dim formu As String
Set a1 = Range("A1")
Set t = Target
If Intersect(a1, t) Is Nothing Then Exit Sub
v = t.Value
If v = "a" Then formu = "=A2+A3"
If v = "b" Then formu = "=A2-A3"
If v = "c" Then formu = "=A2*A3"
If v = "d" Then formu = "=A2/A3"
Application.EnableEvents = False
Range("A4").Formula = formu
Application.EnableEvents = True
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu200859


"JulianP" wrote:

I would like to use a pull down menu to control the formulas in different
cells. For example if the pulldown is set to A then the formula in cells
are one thing. If set to B then the formula in that cell would change to
something else. I have though of using if statements, but this gets messy.
Do I need to get in to macro writing? I am looking for something simple.
Cheers


JulianP

Multiple cell formulas in different cells
 
Thank you. This works for me because I have different formulars for several
cells that depend on the selected option. I will give it a shot. Cheers

"Gary''s Student" wrote:

Say we have a Data Validation drop-down in A1 that selects from:
a,b,c,d
and we want to make the formula in A4:

=A1+A2
or
=A1-A2
or
=A1*A2
or
=A1/A2

Insert the following macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim a1 As Range, t As Range, v As String
Dim formu As String
Set a1 = Range("A1")
Set t = Target
If Intersect(a1, t) Is Nothing Then Exit Sub
v = t.Value
If v = "a" Then formu = "=A2+A3"
If v = "b" Then formu = "=A2-A3"
If v = "c" Then formu = "=A2*A3"
If v = "d" Then formu = "=A2/A3"
Application.EnableEvents = False
Range("A4").Formula = formu
Application.EnableEvents = True
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu200859


"JulianP" wrote:

I would like to use a pull down menu to control the formulas in different
cells. For example if the pulldown is set to A then the formula in cells
are one thing. If set to B then the formula in that cell would change to
something else. I have though of using if statements, but this gets messy.
Do I need to get in to macro writing? I am looking for something simple.
Cheers



All times are GMT +1. The time now is 08:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com