Question : Macro Help

I have a inventory file, I want to keep the log, Now I am just adding or subtracting the qty I issue or receive. I have simple macro written to it. Please if somebody can help in this regards

Answer : Macro Help

Jsadiq,

The code below is in the attached file. It is only a start as a lot of error checking would need to be added to ensure that only good data was entered. However there are quite a few VBA methods involved so it should help you see how a project can be started - because it's only a start and it's far from perfect. Hopefully it gives a few ideas...

Hope it helps

Patrick
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
In UserForm1 code pane:


Private Sub ComboBox1_Change()
'item received
Dim rng As Range
Dim rng_found As Range

With Sheets("summarystk")
    Set rng = Range(.Cells(2, "A"), .Cells(.Rows.Count, "A").End(xlUp))
End With
Set rng_found = rng.Find(Me.ComboBox1.Value, LookIn:=xlValues)
UserForm1.TextBox3 = rng_found.Offset(0, 1).Value
UserForm1.TextBox4 = rng_found.Offset(0, 2).Value

End Sub

Private Sub CommandButton1_Click()
'Submit button
With Sheets("Incoming")
    .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0) = TextBox1.Value
    .Cells(.Rows.Count, "A").End(xlUp).Offset(0, 1) = TextBox4.Value
    .Cells(.Rows.Count, "A").End(xlUp).Offset(0, 2) = TextBox7.Value
    .Cells(.Rows.Count, "A").End(xlUp).Offset(0, 3) = TextBox5.Value
    .Cells(.Rows.Count, "A").End(xlUp).Offset(0, 4) = TextBox6.Value
    .Cells(.Rows.Count, "A").End(xlUp).Offset(0, 5) = ComboBox1.Value
    .Cells(.Rows.Count, "A").End(xlUp).Offset(0, 6) = TextBox2.Value
End With
Unload UserForm1
Call Module1.beginning
End Sub

Private Sub CommandButton4_Click()
'Add new Supplier and Item
UserForm1.Height = 300
End Sub

Private Sub CommandButton6_Click()
'clear new details without saving and continue button
Call clearer
End Sub

Private Sub CommandButton5_Click()
'add new details to database

With Sheets("summarystk")
    'item
    .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0) = UserForm1.TextBox9.Value
    'item description
    .Cells(.Rows.Count, "A").End(xlUp).Offset(0, 1) = UserForm1.TextBox10.Value
    'supplier
    .Cells(.Rows.Count, "A").End(xlUp).Offset(0, 2) = UserForm1.TextBox8.Value
    'insert formula into column E
    .Cells(.Rows.Count, "A").End(xlUp).Offset(0, 4).FormulaR1C1 = _
        "=SUMIF(Incoming!C[1],summarystk!RC[-4],Incoming!C[2])-SUMIF(Outgoing!C[-2],summarystk!RC[-4],Outgoing!C[-1])"
End With

Unload UserForm1
Call Module1.beginning
End Sub

Private Sub clearer()
'clears details of new items and supplier
UserForm1.TextBox8 = ""
UserForm1.TextBox9 = ""
UserForm1.TextBox10 = ""
UserForm1.Height = 190
End Sub

Private Sub CommandButton2_Click()
'Quit
Unload UserForm1
End Sub

In Module1:

Sub beginning()
'set-up data and Userform1
Dim rng As Range
Dim celle As Range
Dim coll As New Collection
Dim i As Long

With Sheets("summarystk")
    .Activate
    Set rng = Range(.Cells(2, "A"), .Cells(.Rows.Count, "A").End(xlUp).Offset(0, 3))
    rng.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlNo, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortTextAsNumbers
    Set rng = Range(.Cells(2, "A"), .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each celle In rng
    UserForm1.ComboBox1.AddItem celle
Next celle

With UserForm1
    .TextBox1 = Date
    .Height = 190
    .Show
End With

End Sub
 
 
Random Solutions  
 
programming4us programming4us