View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Seņor Rubia Seņor Rubia is offline
external usenet poster
 
Posts: 2
Default ComboBox search for variable...

I am doing VBA for a spreadsheet at work. The idea behind this
spreadsheet is to have a UserForm that asks for a certain Month
(cmbMonth) & Day (cmbDate) and Dollar Amount (txt.EndCash). Then,
using the Month, it goes to a certain sheet (named "January",
"February", etc.) and finds the cell with the specific date already in
there, then goes 3 cells to the right to input the dollar amount
specified. So far, I have succeeded in code that specifies the sheet,
but have drawn a blank on something that can assign a variable to
cmbDate and search for it on the sheet in A6:A37.

Here's my current code if that helps out any (most of it applies to
the OK, Cancel & Clear buttons, obviously:

-----------------------------------------
Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdClear_Click()
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox"
Then
ctl.Value = ""
ElseIf TypeName(ctl) = "CheckBox" Then
ctl.Value = False
End If
Next ctl
End Sub

Private Sub cmdOK_Click()

ScreenUpdating = False
Val1 = txtEndCash
TheSheet = cmbMonth.Value
Worksheets(TheSheet).Activate
ActiveSheet.Range("H3") = Val1
ScreenUpdating = True

Dim RowCount As Long
RowCount =
Worksheets("January").Range("D20").CurrentRegion.R ows.Count
With Worksheets("January").Range("D20")
.Offset(RowCount, 0).Value = Me.txtEndCash.Value
End With

If Me.cmbMonth.Value = "" Then
MsgBox "Please Enter A Month!", vbExclamation, "Date Error"
Me.cmbMonth.SetFocus
Exit Sub
End If

If Me.cmbDate.Value = "" Then
MsgBox "Please Enter A Date!", vbExclamation, "Date Error"
Me.cmbDate.SetFocus
Exit Sub
End If

If Me.txtEndCash.Value = "" Then
MsgBox "Please Enter A Dollar Amount!", vbExclamation, "Money
Error"
Me.txtEndCash.SetFocus
Exit Sub
End If

If Me.txtEndCash.Value = "0.00" Then
MsgBox "Please Enter A Dollar Amount!", vbExclamation, "Money
Error"
Me.txtEndCash.SetFocus
Exit Sub
End If

If Not IsNumeric(Me.txtEndCash.Value) Then
MsgBox "Hey, dummy! The END CASH Amount must be a NUMBER!",
vbExclamation, "Money Error"
Me.txtEndCash.SetFocus
Exit Sub
End If


End Sub



Private Sub UserForm_Click()

End Sub


--------

Thanks in advance for any help!