Need Help With a VBA formula

AMac2310

New Member
Joined
Sep 19, 2016
Messages
1
I'm trying to create a form that a user can easily enter data into a spreadsheet. I have a code written but it is erroring out on me. Any help at where I'm going wrong would be appreciated.

Code:
Private Sub DataEntry_Initialize()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'Empty txtD
 txtD.Value = ""
'Empty txtTime
 txtTime.Value = ""
'Empty txtClerk
 txtClerk.Value = ""
 
'Empty txtProduct
 txtProduct.Value = ""
 
'Empty lstLane
 lstLane.Clear
 
'Fill lstLane
With lstLane
     .AddItem "1"
     .AddItem "2"
     .AddItem "3"
     .AddItem "4"
     .AddItem "5"
     .AddItem "6"
     .AddItem "7"
     .AddItem "8"
     .AddItem "9"
     .AddItem "10"
     .AddItem "11"
     .AddItem "12"
     .AddItem "13"
     .AddItem "14"
     .AddItem "15"
     .AddItem "Grief Bay"
     .AddItem "Quality Bay"
     .AddItem "Balance Bay"
End With
'Empty lstHU
 lstHU.Clear
 
'Fill lstHU
With lstLane
.AddItem "AE"
.AddItem "AR"
.AddItem "AT"
.AddItem "AU"
.AddItem "BA"
.AddItem "BB"
.AddItem "BE"
.AddItem "BG"
.AddItem "BO"
.AddItem "BR"
.AddItem "BS"
.AddItem "BW"
.AddItem "BY"
.AddItem "BZ"
.AddItem "CA"
.AddItem "CH"
.AddItem "CL"
.AddItem "CN"
.AddItem "CO"
.AddItem "CR"
.AddItem "CU"
.AddItem "CZ"
.AddItem "DE"
.AddItem "DE"
.AddItem "DK"
.AddItem "EC"
.AddItem "EG"
.AddItem "ES"
.AddItem "ES"
.AddItem "FI"
.AddItem "FR"
.AddItem "GB"
.AddItem "GP"
.AddItem "GR"
.AddItem "GT"
.AddItem "GU"
.AddItem "GY"
.AddItem "HK"
.AddItem "HN"
.AddItem "HT"
.AddItem "HU"
.AddItem "ID"
.AddItem "IE"
.AddItem "IL"
.AddItem "IN"
.AddItem "IT"
.AddItem "JM"
.AddItem "JO"
.AddItem "JP"
.AddItem "KE"
.AddItem "KN"
.AddItem "KR"
.AddItem "KY"
.AddItem "LI"
.AddItem "LU"
.AddItem "MC"
.AddItem "MM"
.AddItem "MO"
.AddItem "MQ"
.AddItem "MT"
.AddItem "MX"
.AddItem "MY"
.AddItem "NE"
.AddItem "NI"
.AddItem "NL"
.AddItem "NO"
.AddItem "NZ"
.AddItem "PA"
.AddItem "PE"
.AddItem "PF"
.AddItem "PH"
.AddItem "PK"
.AddItem "PL"
.AddItem "PR"
.AddItem "PT"
.AddItem "PY"
.AddItem "RE"
.AddItem "RO"
.AddItem "RU"
.AddItem "SA"
.AddItem "SE"
.AddItem "SG"
.AddItem "SI"
.AddItem "SK"
.AddItem "SR"
.AddItem "SV"
.AddItem "TH"
.AddItem "TN"
.AddItem "TR"
.AddItem "TT"
.AddItem "TW"
.AddItem "UA"
.AddItem "US"
.AddItem "UY"
.AddItem "UZ"
.AddItem "VE"
.AddItem "VN"
.AddItem "YU"
.AddItem "ZA"
.AddItem "ZW"
End With
'Empty lstCoO
 LstCoO.Clear
 
'Fill lstCoO
With LstCoO
.AddItem "AE"
.AddItem "AR"
.AddItem "AT"
.AddItem "AU"
.AddItem "BA"
.AddItem "BB"
.AddItem "BE"
.AddItem "BG"
.AddItem "BO"
.AddItem "BR"
.AddItem "BS"
.AddItem "BW"
.AddItem "BY"
.AddItem "BZ"
.AddItem "CA"
.AddItem "CH"
.AddItem "CL"
.AddItem "CN"
.AddItem "CO"
.AddItem "CR"
.AddItem "CU"
.AddItem "CZ"
.AddItem "DE"
.AddItem "DE"
.AddItem "DK"
.AddItem "EC"
.AddItem "EG"
.AddItem "ES"
.AddItem "ES"
.AddItem "FI"
.AddItem "FR"
.AddItem "GB"
.AddItem "GP"
.AddItem "GR"
.AddItem "GT"
.AddItem "GU"
.AddItem "GY"
.AddItem "HK"
.AddItem "HN"
.AddItem "HT"
.AddItem "HU"
.AddItem "ID"
.AddItem "IE"
.AddItem "IL"
.AddItem "IN"
.AddItem "IT"
.AddItem "JM"
.AddItem "JO"
.AddItem "JP"
.AddItem "KE"
.AddItem "KN"
.AddItem "KR"
.AddItem "KY"
.AddItem "LI"
.AddItem "LU"
.AddItem "MC"
.AddItem "MM"
.AddItem "MO"
.AddItem "MQ"
.AddItem "MT"
.AddItem "MX"
.AddItem "MY"
.AddItem "NE"
.AddItem "NI"
.AddItem "NL"
.AddItem "NO"
.AddItem "NZ"
.AddItem "PA"
.AddItem "PE"
.AddItem "PF"
.AddItem "PH"
.AddItem "PK"
.AddItem "PL"
.AddItem "PR"
.AddItem "PT"
.AddItem "PY"
.AddItem "RE"
.AddItem "RO"
.AddItem "RU"
.AddItem "SA"
.AddItem "SE"
.AddItem "SG"
.AddItem "SI"
.AddItem "SK"
.AddItem "SR"
.AddItem "SV"
.AddItem "TH"
.AddItem "TN"
.AddItem "TR"
.AddItem "TT"
.AddItem "TW"
.AddItem "UA"
.AddItem "US"
.AddItem "UY"
.AddItem "UZ"
.AddItem "VE"
.AddItem "VN"
.AddItem "YU"
.AddItem "ZA"
.AddItem "ZW"
End With
'Empty txtQuantity
 txtQuantity.Value = ""
'Empty txtAssociate
 txtAssociate.Value = ""
'Empty lstGRFType
 GRFType.Clear
 
'Fill lstGRFType
With lstGRFType
.AddItem "ADPR"
.AddItem "Allocation Recall"
.AddItem "ASN"
.AddItem "Auto Grief"
.AddItem "BTS"
.AddItem "CoO"
.AddItem "Damaged Packaging"
.AddItem "Damaged Product"
.AddItem "Expired Product"
.AddItem "Found Product"
.AddItem "Gross Overage"
.AddItem "Incorrect VAS / GPP"
.AddItem "IT"
.AddItem "Manual ASN"
.AddItem "Mislabeled Product"
.AddItem "Missing HU"
.AddItem "Missing Product"
.AddItem "Mixed Product"
.AddItem "MRR"
.AddItem "Quality"
.AddItem "Rejection"
.AddItem "Return"
.AddItem "Scrap"
.AddItem "Shortage After SUSH"
.AddItem "Supplier Wrong Part"
.AddItem "Unscheduled"
.AddItem "Wrong Product"
.AddItem "Other"
End With
'Empty txtComments
txtComments.Value = ""
'Set Focus on txtD
txtD.SetFocus
End Sub
Sub DataEntry()

'Make MasterGriefLog active
 MasterGriefLog.Activate

'Determine emptyRow
 emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Transfer information
 Cells(emptyRow, 1).Value = txtD.Value
 Cells(emptyRow, 2).Value = txtTime.Value
 Cells(emptyRow, 3).Value = txtClerk.Value
 Cells(emptyRow, 4).Value = txtProduct.Value
 Cells(emptyRow, 5).Value = lstLane.Value
 Cells(emptyRow, 6).Value = lstHU.Value
 Cells(emptyRow, 7).Value = LstCoO.Value
 Cells(emptyRow, 8).Value = txtQuantity.Value
 Cells(emptyRow, 9).Value = txtAssociate.Value
 Cells(emptyRow, 10).Value = lstGRFType.Value
 Cells(emptyRow, 11).Value = txtComments.Value
End Sub
 
 
Private Sub CommandButton2_Click()
Call UserForm_Initialize
End Sub
Private Sub txtComments_Change()
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
 
Last edited by a moderator:

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

RickXL

MrExcel MVP
Joined
Sep 9, 2013
Messages
4,328
Hi and welcome to the MrExcel Message Board.

If you could say what the error message is and where it occurs that might help.

However, first a question. Do you mean lstLane here:
Code:
'Empty lstHU
 lstHU.Clear
 
'Fill lstHU
With lstLane
.AddItem "AE"


Regards,
 

Watch MrExcel Video

Forum statistics

Threads
1,128,086
Messages
5,628,591
Members
416,326
Latest member
NinaChristal

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
Top