Help With VBA Coding
1. Add UserForm1
userform1 exported data
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} UserForm1
Caption = "User Option"
ClientHeight = 3585
ClientLeft = 45
ClientTop = 390
ClientWidth = 6420
OleObjectBlob = "UserForm1.frx":0000
StartUpPosition = 1 'CenterOwner
End
Attribute VB_Name = "UserForm1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub CommandButton1_Click()
If (opadd.Value = True) Then
Call AddNewData
End If
End Sub
Private Sub AddNewData()
Dim rownum As Long
rownum = Sheet1.Cells(rows.Count, 1).End(xlUp).Row
Module1.currRow = rownum + 1
If (rownum = 1) Then
Module1.currDate = Now
Else
Module1.currDate = Sheet1.Cells(rownum, 1)
End If
UserForm2.lblheading.Caption = "Enter the newly observer demand and
cost data of " & MonthName(Month(Module1.currDate)) & "-"
& Year(Module1.currDate)
UserForm2.Show
End Sub
Private Sub CommandButton2_Click()
UserForm1.Hide
End Sub
2. userform2
exported userform2 data
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} UserForm2
Caption = "UserForm2"
ClientHeight = 2505
ClientLeft = 45
ClientTop = 390
ClientWidth = 4710
OleObjectBlob = "UserForm2.frx":0000
StartUpPosition = 1 'CenterOwner
End
Attribute VB_Name = "UserForm2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub CommandButton1_Click()
If IsNumeric(tbxdemand.Text) = True And IsNumeric(tbxCost.Text)
= True Then
Sheet1.Cells(Module1.currRow, 1) =
MonthName(Month(Module1.currDate)) & "-" &
Year(Module1.currDate)
Sheet1.Cells(Module1.currRow, 2) = UserForm2.tbxdemand.Text
Sheet1.Cells(Module1.currRow, 3) = UserForm2.tbxCost.Text
UserForm2.Hide
Else
MsgBox ("Enter valid values")
End If
End Sub
3. Module code to open form
Public currDate As Date
Public currRow As Long
Sub ShowUserOptions()
UserForm1.Show
End Sub
scrrenshots
for run macro
Help With VBA Coding User options OK Select one of the following options: Options Cancel Find an optimal production plan C View demand and cost data Enter new demand and cost data C Change smoothing...