compute column a and column b and show result in column c

roipatrick

New Member
Joined
Mar 20, 2014
Messages
39
Hi and Good day to all of you,

I want to add 2 cells, lets say for example, take a look on the table below

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Column A[/TD]
[TD]Column B[/TD]
[TD]Column C[/TD]
[/TR]
[TR]
[TD]2000[/TD]
[TD]2[/TD]
[TD]4000[/TD]
[/TR]
[TR]
[TD]1000[/TD]
[TD]5[/TD]
[TD]5000[/TD]
[/TR]
[TR]
[TD]200[/TD]
[TD]6[/TD]
[TD]1200[/TD]
[/TR]
[TR]
[TD]100[/TD]
[TD]8[/TD]
[TD]800[/TD]
[/TR]
</tbody>[/TABLE]

As you can see, I want column C to render the product of column a and b, Take note that I want this to be done in macro VBA code and not in formulas.

Thank you in advance to all of you guys,

So new here in VBA as in super new.
 
Is that table of equivalent values fixed and constant (meaning it will never change, so that it can be hard-coded within the macro itself) or is what you posted only a simplified example and the real table is longer are more variable than shown? If the latter, do you have this table existing on a worksheet somewhere? If so, what is the sheet name and range for the table... if not, then you will need to put the table somewhere and then tell us the sheet name and range where you put it.


Im Sorry sir if i cant answer you question correctly since im having a hard time understanding english...:( anyways...i just need the idea and ill try it myself....can you give me a sample on how to do it..the one In my post of 1=5 and 2 = 10 and so on.

Thanks.
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Where is this table at... what sheet name, what cells?


Actually its not the table......
Ill show you and thanks for the patience..

[TABLE="width: 500"]
<tbody>[TR]
[TD]Column A[/TD]
[TD]Column B[/TD]
[TD]Column C[/TD]
[/TR]
[TR]
[TD]100[/TD]
[TD]1[/TD]
[TD]500[/TD]
[/TR]
[TR]
[TD]200[/TD]
[TD]2[/TD]
[TD]2000[/TD]
[/TR]
</tbody>[/TABLE]


So basically the 1 = 5 and the 2 is equals to 10......so meaning that 100*(1*5) = 500
And 200 (2*10) = 2000

the 1 = 5 and 2 = 10 is constant....i just want to show the 1 and 2 in the table...

Thanks.
 
Last edited:
Upvote 0
The pattern that I see is that you would increment the numbers by 5

so if you had

column A = 100
column b = 6
you would do (6*5)*100 = 3000

or not?
 
Upvote 0
The pattern that I see is that you would increment the numbers by 5

so if you had

column A = 100
column b = 6
you would do (6*5)*100 = 3000

or not?


No Sir,

Column b are constant upto 3.

So

1= 5
2=10
3=15

1,2 and 3 will appear many times in column b as 1,2,3 or as 3,1,2 or 2,3,1 so its value are constant.

Now column A is lets say price.. How will I do it?

Hope you get my point and thank you for your patience.
 
Upvote 0
No Sir,

Column b are constant upto 3.

So

1= 5
2=10
3=15

1,2 and 3 will appear many times in column b as 1,2,3 or as 3,1,2 or 2,3,1 so its value are constant.
Here is my original code modified for this relationship, see if it works for you...
Code:
Sub ColumnCequalsColumnAtimesColumnB()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Range("C1:C" & LastRow) = Evaluate(Replace("5*A1:A#*B1:B#", "#", LastRow))
End Sub
 
Upvote 0
Here is my original code modified for this relationship, see if it works for you...
Code:
Sub ColumnCequalsColumnAtimesColumnB()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Range("C1:C" & LastRow) = Evaluate(Replace("5*A1:A#*B1:B#", "#", LastRow))
End Sub

Here's a more detailed problem Sir,anyways thanks for being so petient

I tried doing a code but probably this is not correct at all


Code:
For Each Cell.Range(C1,C#)
If Range("C1:C" & LastRow) = "1" Then
Compute ((C1*5) * D1) = B1 (B1 is where the result should show)
Else If ("C1:C" & LastRow) = "2" Then
Compute ((C1*15) * D1) = B1 (B1 is where the result should show)
Else If ("C1:C" & LastRow) = "4" Then
Compute ((C1*20) * D1) = B1 (B1 is where the result should show)
Loop

Hope I delivered the problem correctly.
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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