Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50151

How to use VBA to set formula?

$
0
0
For instances, I wanna set 2 formula via VBA, one is to calculate the accumulated balance,
the first formula is the 2nd balance= 1st balance + 2nd quantity received (if any) - 2nd quantity supplied (if any)
the second formula is the total quantity received within a period of time

As for the formula 1, I design to set a userform for users to enter the start balance of each item,
but I cant restrict the users to enter the balance again for the same item code...
Here is my code and excel file.
Code:

For i = 3 To Sheets(2).Cells(Rows.Count, 3).End(xlUp).Row
 If Sheets(2).Cells(i, 2).Value = "Product A" Then
textbox_startbalance.Value = ""
textbox_startbalance.Enabled = False
textbox_startbalance.BackColor = vbGrey
textbox_startbalance.Value = ""
textbox_startbalance.Enabled = True
textbox_startbalance.BackColor = vbWhite
MsgBox " You have already entered the start balance before",vbCritical
Exit Sub
    End If
Next i

Then, if I successfully restrict the users enter the balance again for the same item code, I will put the following code in sheet or userform.

am I right?

As for the formula 2, I will use the search function to search one of the particular item code (e.g. ABCD01)
between the start date (e.g.1.5.2013) and the end date(e.g.31.5.2013)
Then, and use countif the quantity received within these data, am I right?
Attached Files

Viewing all articles
Browse latest Browse all 50151

Trending Articles