#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macros/VBA

I have a column D where the values of D's cells are
dependent on cells A, B, and C of that row. Once A, B, or
C is changed, I want the calculation for D to be updated.
How do I create a macro with VBA that will do this? (I
believe I need a macro because the conditional statements
are very tedious and complex by using nested ands and ors.)

Thanks very much.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Macros/VBA

A User-Defined Function should do what you want.

Function FillCell(rngA As Range, rngB As Range, rngC As Range) As
Variant

Application.Volatile

If rngA.Value = "o" And rngB.Value = "m" And rngC.Value = "l" Then
FillCell = 87
ElseIf rngA.Value = "o" And rngB.Value = 1 And rngC.Value = 6 Then
FillCell = 65
ElseIf ' As many combos as you need.
Else
FillCell = "Combination not valid."
End If

End Function

---------------------------------------------------------------------------------
Place this formula in Cell D1.

=FillCell(A1,B1,C1)

---------------------------------------------------------------------------------

When you change any of the values in the three cells, the value in D1
should change.

You can copy this function down Column D as many times as needed.

You'll need to adjust the code to get the combination that you're
seeking.

HTH
Paul
--------------------------------------------------------------------------------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------------------------------------------------------------
On Wed, 3 Sep 2003 12:44:51 -0700, "mika"
wrote:

I have a column D where the values of D's cells are
dependent on cells A, B, and C of that row. Once A, B, or
C is changed, I want the calculation for D to be updated.
How do I create a macro with VBA that will do this? (I
believe I need a macro because the conditional statements
are very tedious and complex by using nested ands and ors.)

Thanks very much.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Macros/VBA

Mika,

This may actually work better without a Macro.

Try this.
In a new worksheet create the following table
(It is possible to do this within your existing sheet but I like to do
tables outside my input sheet)

two columns

a b
"bmO" 2
"bmT" 2
"bnMF" 3
........ thousands of combinations are possible.
The text string should match the combination you desire to choose and can be
any length.
This new sheet can be Hidden if you desire so users never see it,
You can maintain your options easily without touching any code.

Name these columns as a range. Use something convenient. "Options"
perhaps.
Now on your first sheet the formula in a4 would look something like this.

=vlookup(concatenate(a1,a2,a3),options,2,false)

What your doing is simply creating a text string from your choices.
Then looking that string up in a table to get the result that matches the
value from Column b on the new sheet.

The vlookup can be used again and again.

Hope this helps

Gary M.


wrote in message
...
A User-Defined Function should do what you want.

Function FillCell(rngA As Range, rngB As Range, rngC As Range) As
Variant

Application.Volatile

If rngA.Value = "o" And rngB.Value = "m" And rngC.Value = "l" Then
FillCell = 87
ElseIf rngA.Value = "o" And rngB.Value = 1 And rngC.Value = 6 Then
FillCell = 65
ElseIf ' As many combos as you need.
Else
FillCell = "Combination not valid."
End If

End Function

--------------------------------------------------------------------------

-------
Place this formula in Cell D1.

=FillCell(A1,B1,C1)

--------------------------------------------------------------------------

-------

When you change any of the values in the three cells, the value in D1
should change.

You can copy this function down Column D as many times as needed.

You'll need to adjust the code to get the combination that you're
seeking.

HTH
Paul
--------------------------------------------------------------------------

------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------------------------

------------------------------------
On Wed, 3 Sep 2003 12:44:51 -0700, "mika"
wrote:

I have a column D where the values of D's cells are
dependent on cells A, B, and C of that row. Once A, B, or
C is changed, I want the calculation for D to be updated.
How do I create a macro with VBA that will do this? (I
believe I need a macro because the conditional statements
are very tedious and complex by using nested ands and ors.)

Thanks very much.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Macros/VBA

Hi Gary,

This is what I put down:
=VLOOKUP(CONCATENATE(O3,"#",S3,"#",R3,"#",P3),OSRP ,2,FALSE)
OSRP is the name of column A in my other sheet, and the
values I want to be inputed in my dependent cell are in
column B of the other sheet.

I did the # because I am allowed to have blank values for
O3, S3, R3 and P3.

But for the above statement, I get an error saying "the
macros int his project are disabled" and then #NAME?
appears.

Any suggestsions?

Thanks,
mika.
-----Original Message-----
Mika,

This may actually work better without a Macro.

Try this.
In a new worksheet create the following table
(It is possible to do this within your existing sheet

but I like to do
tables outside my input sheet)

two columns

a b
"bmO" 2
"bmT" 2
"bnMF" 3
........ thousands of combinations are possible.
The text string should match the combination you desire

to choose and can be
any length.
This new sheet can be Hidden if you desire so users never

see it,
You can maintain your options easily without touching any

code.

Name these columns as a range. Use something

convenient. "Options"
perhaps.
Now on your first sheet the formula in a4 would look

something like this.

=vlookup(concatenate(a1,a2,a3),options,2,false)

What your doing is simply creating a text string from

your choices.
Then looking that string up in a table to get the result

that matches the
value from Column b on the new sheet.

The vlookup can be used again and again.

Hope this helps

Gary M.


wrote in message
.. .
A User-Defined Function should do what you want.

Function FillCell(rngA As Range, rngB As Range, rngC As

Range) As
Variant

Application.Volatile

If rngA.Value = "o" And rngB.Value = "m" And

rngC.Value = "l" Then
FillCell = 87
ElseIf rngA.Value = "o" And rngB.Value = 1 And

rngC.Value = 6 Then
FillCell = 65
ElseIf ' As many combos as you need.
Else
FillCell = "Combination not valid."
End If

End Function

--------------------------------------------------------

------------------
-------
Place this formula in Cell D1.

=FillCell(A1,B1,C1)

--------------------------------------------------------

------------------
-------

When you change any of the values in the three cells,

the value in D1
should change.

You can copy this function down Column D as many times

as needed.

You'll need to adjust the code to get the combination

that you're
seeking.

HTH
Paul
--------------------------------------------------------

------------------
------------------------------------
Be advised to back up your WorkBook before attempting

to make changes.
--------------------------------------------------------

------------------
------------------------------------
On Wed, 3 Sep 2003 12:44:51 -0700, "mika"


wrote:

I have a column D where the values of D's cells are
dependent on cells A, B, and C of that row. Once A,

B, or
C is changed, I want the calculation for D to be

updated.
How do I create a macro with VBA that will do this? (I
believe I need a macro because the conditional

statements
are very tedious and complex by using nested ands and

ors.)

Thanks very much.




.

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
Excel 2007 macros - how to merge 5 macros together into one Sue Excel Discussion (Misc queries) 1 April 16th 08 08:36 PM
Macros warning always shows up, even if all macros removed Joe M Excel Discussion (Misc queries) 1 December 20th 07 04:45 AM
Macros - copying macros from one computer to another TT Excel Discussion (Misc queries) 18 December 14th 06 03:24 AM
Training: More on how to use macros in Excel: Recording Macros ToriT Excel Worksheet Functions 2 February 10th 06 07:05 PM
List the Macros that can be executed from Tools-Macros Rob Bovey Excel Programming 1 July 10th 03 05:34 PM


All times are GMT +1. The time now is 12:19 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"