Equations using VBA with a userform

hephensause

New Member
Joined
Mar 18, 2014
Messages
2
Hello,
This is my first post so bare with me. I am extremely new to VBA. I am creating a database using excel. I am trying to write a code for an equation that will use numbers inputted to my spreadsheet via a userform. The equation should take three values, say A, B, and C. Run them through the formula (A+B)/2C. I want that value to be put in a specific cell in a specific row that my values A,B, and C, refer to. Right now I simply am trying

Code:
Private Sub ScanEnter_Click()
Dim c As Range, front As Single, back As Single, across As Single, ab As Single, twoc As Single, eq As Single
Set c = ActiveCell

c.Offset(1).EntireRow.Insert

Cells(c.Row, 7).Copy Cells(c.Row + 1, 7)
Cells(c.Row + 1, 11).Value = TextBox1.Value
Cells(c.Row + 1, 13).Value = typecombo.Value
Cells(c.Row + 1, 14).Value = fronttxtb.Value
Cells(c.Row + 1, 15).Value = backtxtb.Value
Cells(c.Row + 1, 16).Value = acrosstxtb.Value
Cells(c.Row + 1, 18).Value = shcombo.Value

    front = frontaltxtb.Value
    back = backtxtb.Value
    across = acrosstxtb.Value
    ab = front + back
    twoc = 2 * across
    eq = ab / twoc
    eq = Cells(c.Row + 1, 17).Value




End Sub
[code/]

Any help would be appreciated. Thank you.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
As no one has replied, here is my reply:
Hope you need to change
Code:
eq = Cells(c.Row + 1, 17).Value
as
Code:
Cells(c.Row + 1, 17).Value = eq

The following code
Code:
eq = ab / twoc
can be written as
Code:
eq=(front + back)/(2*across)
which will avoid the variables ab and twoc.

You also need to change [code/] as [/code]
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,237
Members
448,555
Latest member
RobertJones1986

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