Hi everyone,
I have inherited a spreadsheet that is pretty much controlled via VBA, it contains several forms, on one of the forms there is code so that if certain people are using it then they can do more than the ordinary user however it is quite long and cumbersome to administer and i was wondering if someone could perhaps help to give me some ideas on how to streamline it. The code is shown below
Any help would be appreciated bearing in mind my limited knowledge
Regards
Olly
I have inherited a spreadsheet that is pretty much controlled via VBA, it contains several forms, on one of the forms there is code so that if certain people are using it then they can do more than the ordinary user however it is quite long and cumbersome to administer and i was wondering if someone could perhaps help to give me some ideas on how to streamline it. The code is shown below
Code:
Private Sub cmdUpDate_Click()
Dim Prow, Pcol, Mcol, Ncol, Qcol, Tcell As Long
Prow = Range("L1").Value 'These Values are assigned from
Pcol = Range("M1").Value 'the worksheet code realting to the
Mcol = Range("N1").Value ' appropiate command button and then
Qcol = Range("O1").Value 'uses the value from the textboxes and labels
Ncol = Range("P1").Value 'to insert into the spreadsheet
Tcell = Range("Q1").Value
Sheets("FlatBeds").Cells(Prow, Pcol).Value = txtCust.Value
Sheets("FlatBeds").Cells(Prow, Mcol).Value = txtMB.Value & txtDash.Value & TxtItem.Value
Sheets("FlatBeds").Cells(Prow, Qcol).Value = txtQty.Value
Sheets("FlatBeds").Cells(Prow, Ncol).Value = lblUserName.Caption
If (txtCust.Value = "") Or (txtMB.Value = "") Or (TxtItem.Value = "") Or (txtQty.Value = "") Then
Sheets("FlatBeds").Cells(Prow, Pcol).Value = ""
Sheets("FlatBeds").Cells(Prow, Mcol).Value = ""
Sheets("FlatBeds").Cells(Prow, Qcol).Value = ""
Sheets("FlatBeds").Cells(Prow, Ncol).Value = ""
txtCust.Value = Clear
txtMB.Value = Clear
txtDash.Value = Clear
TxtItem.Value = Clear
txtQty.Value = Clear
lblUserName.Caption = Clear
txtCust.SetFocus
MsgBox "WARNING" & vbCrLf & vbCrLf & "ALL FIELDS MUST CONTAIN DATA", 48, "Missing Data"
Else
If (Sheets("FlatBeds").Cells(Prow, Qcol).Value > Tcell) _
And (Sheets("FlatBeds").Cells(Prow, Ncol).Value = "SSams") Then 'If this argument is true then the
Sheets("FlatBeds").Cells(Prow, Pcol).Value = txtCust.Value ' values are assigned, otherwise the
Sheets("FlatBeds").Cells(Prow, Mcol).Value = txtMB.Value & txtDash.Value & TxtItem.Value 'Message box is invoked
Sheets("FlatBeds").Cells(Prow, Qcol).Value = txtQty.Value
Sheets("FlatBeds").Cells(Prow, Ncol).Value = lblUserName.Caption
Else
If (Sheets("FlatBeds").Cells(Prow, Qcol).Value > Tcell) _
And (Sheets("FlatBeds").Cells(Prow, Ncol).Value = "SFaulkner") Then 'If this argument is true then the
Sheets("FlatBeds").Cells(Prow, Pcol).Value = txtCust.Value ' values are assigned, otherwise the
Sheets("FlatBeds").Cells(Prow, Mcol).Value = txtMB.Value & txtDash.Value & TxtItem.Value 'Message box is invoked
Sheets("FlatBeds").Cells(Prow, Qcol).Value = txtQty.Value
Sheets("FlatBeds").Cells(Prow, Ncol).Value = lblUserName.Caption
Else
If (Sheets("FlatBeds").Cells(Prow, Qcol).Value > Tcell) _
And (Sheets("FlatBeds").Cells(Prow, Ncol).Value = "POliver") Then 'If this argument is true then the
Sheets("FlatBeds").Cells(Prow, Pcol).Value = txtCust.Value ' values are assigned, otherwise the
Sheets("FlatBeds").Cells(Prow, Mcol).Value = txtMB.Value & txtDash.Value & TxtItem.Value 'Message box is invoked
Sheets("FlatBeds").Cells(Prow, Qcol).Value = txtQty.Value
Sheets("FlatBeds").Cells(Prow, Ncol).Value = lblUserName.Caption
Else
If (Sheets("FlatBeds").Cells(Prow, Qcol).Value <= Tcell) Then 'If this argument is true then the
Sheets("FlatBeds").Cells(Prow, Pcol).Value = txtCust.Value ' values are assigned, otherwise the
Sheets("FlatBeds").Cells(Prow, Mcol).Value = txtMB.Value & txtDash.Value & TxtItem.Value 'Message box is invoked And when the OK
Sheets("FlatBeds").Cells(Prow, Qcol).Value = txtQty.Value 'button is pressed, the values are cleared
Sheets("FlatBeds").Cells(Prow, Ncol).Value = lblUserName.Caption
Else
If (Sheets("FlatBeds").Cells(Prow, Qcol).Value > Tcell) _
And (Sheets("FlatBeds").Cells(Prow, Ncol).Value = "") Then
Sheets("FlatBeds").Cells(Prow, Pcol).Value = "" 'the cells and the form boxes are
Sheets("FlatBeds").Cells(Prow, Mcol).Value = "" 'cleared and the focus is reset to
Sheets("FlatBeds").Cells(Prow, Qcol).Value = "" 'the Customer text box
Sheets("FlatBeds").Cells(Prow, Ncol).Value = ""
txtCust.Value = Clear
txtMB.Value = Clear
TxtItem.Value = Clear
txtDash.Value = Clear
txtQty.Value = Clear
lblUserName.Caption = Clear
txtCust.SetFocus
Else
MsgBox "WARNING" & vbCrLf & vbCrLf & _
"This orders Qty exceeds the available Qty, your Order wiil not be placed" & vbCrLf & vbCrLf & _
"Only an Authorised User may enter this order", 48, "Machine Overload"
Sheets("FlatBeds").Cells(Prow, Pcol).Value = "" 'If none of the above are True then
Sheets("FlatBeds").Cells(Prow, Mcol).Value = "" 'the cells and the form boxes are
Sheets("FlatBeds").Cells(Prow, Qcol).Value = "" 'cleared and the focus is reset to
Sheets("FlatBeds").Cells(Prow, Ncol).Value = "" 'the Customer text box
txtCust.Value = Clear
txtMB.Value = Clear
TxtItem.Value = Clear
txtDash.Value = Clear
txtQty.Value = Clear
lblUserName.Caption = Clear
txtCust.SetFocus
End
End If
End If
End If
End If
End If
End If
End Sub
Any help would be appreciated bearing in mind my limited knowledge
Regards
Olly