PC Review


Reply
Thread Tools Rate Thread

ComboBox search for variable...

 
 
Seņor Rubia
Guest
Posts: n/a
 
      17th Jan 2008
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.Rows.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!
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      17th Jan 2008
Maybe you can fit this into your code:

Dim res as variant
dim myRng as range

with worksheets(TheSheet)
set myrng = .range("a6:a37")
'cmbdate.value is text.
'I'm guessing that the values in A6:A37 are really numbers
res = application.match(clng(cmbdate.value),myrng,0)
if iserror(res) then
msgbox "That date isn't on " & .name & "!"
else
myrng(res).offset(0,3).value = txtEndCash 'not txt.endcash???
end if
end with

Seņor Rubia wrote:
>
> 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.Rows.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!


--

Dave Peterson
 
Reply With Quote
 
Seņor Rubia
Guest
Posts: n/a
 
      22nd Jan 2008
On Jan 17, 10:49*am, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> Maybe you can fit this into your code:
>
> Dim res as variant
> dim myRng as range
>
> with worksheets(TheSheet)
> * *set myrng = .range("a6:a37")
> * *'cmbdate.value is text. *
> * *'I'm guessing that the values in A6:A37 are really numbers
> * *res = application.match(clng(cmbdate.value),myrng,0)
> * *if iserror(res) then
> * * * msgbox "That date isn't on " & .name & "!"
> * *else
> * * * myrng(res).offset(0,3).value = txtEndCash 'not txt.endcash???
> * *end if
> end with
>
>
>
>
>
> Seņor Rubia wrote:
>
> > 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.Rows.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!

>
> --
>
> Dave Peterson- Hide quoted text -
>
> - Show quoted text -


Seems to work good. Thanks!!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error testing combobox to variable gwoodby@gmail.com Microsoft Excel Programming 5 15th Nov 2007 05:14 PM
Refer to combobox in userform with variable lif Microsoft Excel Programming 8 25th Jun 2006 11:21 AM
Can Combobox range be variable? Matt Microsoft Excel Programming 3 6th Oct 2005 08:15 PM
Variable ComboBox on Userform DHallam Microsoft Excel Programming 2 19th Jul 2005 12:20 PM
Set Up Public Object and ComboBox variable =?Utf-8?B?R3doaXQ=?= Microsoft Access VBA Modules 2 17th May 2005 12:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:49 AM.