VBA to create simple stock control

maiwarits

New Member
Joined
Jul 17, 2022
Messages
34
Office Version
  1. 365
Platform
  1. Windows
Hello guys!

I have tried to create simple stock control in my laboratory.
However, I'm very new for VBA, So, I can create only easy VBA [from my little knowledge.].

So, I will try to explain my expectation in the below detail. Kindly help!

This is my simple project code.

VBA Code:
Sub addStock()

Dim balanceStock As Double
balanceStock = InputBox("Amount?")
ActiveCell.Value = ActiveCell.Value + balanceStock

End Sub

1717570399920.png

Active cell = E5, Date = 6June2024
If I input 5 in text box, 5 should go in E5 by ActiveCell.Value = ActiveCell.Value + 5.
At Jun (Column R) 5 value should go in the cell R7 of Jun by ActiveCell.Value = ActiveCell.Value + 5.also.

Active cell = E5, Date = 6June2024
If I input -5 in text box, -5 should go in E5 by ActiveCell.Value = ActiveCell.Value + (-5).
At Jun (Column R) -5 value should go in the cell S7 of Jun by ActiveCell.Value = ActiveCell.Value + (-5) also .



I'm not sure , I have explained to making you all clear or not.
But If you have any question or require more information, please let me know.

I appreciate you all in advance.
Thanks!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
@maiwarits Does this help?

VBA Code:
Sub addStock()

Dim balanceStock As Double
Dim Col As Integer
'Check imput Applies columns E & F only ??
If ActiveCell.Column < 5 Or ActiveCell.Column > 6 Then Exit Sub

Col = Month(Now) + 12

balanceStock = InputBox("Amount?")

With ActiveCell
    .Value = .Value + balanceStock
    If balanceStock < 0 Then Col = Col + 1
    Cells(.Row, Col) = Cells(.Row, Col) + balanceStock
End With

End Sub
 
Upvote 0
Solution
@maiwarits Does this help?

VBA Code:
Sub addStock()

Dim balanceStock As Double
Dim Col As Integer
'Check imput Applies columns E & F only ??
If ActiveCell.Column < 5 Or ActiveCell.Column > 6 Then Exit Sub

Col = Month(Now) + 12

balanceStock = InputBox("Amount?")

With ActiveCell
    .Value = .Value + balanceStock
    If balanceStock < 0 Then Col = Col + 1
    Cells(.Row, Col) = Cells(.Row, Col) + balanceStock
End With

End Sub
Dear Sir!

This code work perfectly!
I appreciate your help a lot!

Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,961
Messages
6,175,652
Members
452,664
Latest member
alpserbetli

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