LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default 2 If/Then statements in 1 sub not working correctly

I have messed around with this for a couple days. This should be so
simple, but I can’t get it right.

When user hits the OK button, I want VBA to check the entry of
TextBox2 VS the range value of Base_Pay.
If the TextBox2 value is less, then execute 1 routine. If it’s more,
then a different routine. It won’t seem to recognize if its less, so
nothing happens. No error.

If I take out the top part (less than), and just leave in the If More
part, then it works fine. Why can’t I get the top section for If Less
to work? Is there something about the less than < sign VBA doesn’t
like? Do I need to make Declarations?
Note: TextBox1 shows current date.
Thanks for your help.
j.o.

Private Sub CommandButton2_Click()
'OK button

‘1st section checks to see if TextBox2 is less than
range Base_Pay

‘ ***I’ve tried this statement both ways, neither works***
'If Range("Base_Pay").Value (TextBox2.Value) Then
If (TextBox2.Value) < Range("Base_Pay").Value Then

Application.Goto Reference:="Account_1"
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.Value = TextBox1.Value
ActiveCell.Offset(0, 3).Select ‘Goes to Debt column
'ActiveCell.Value = Range("Base_Pay").Value - TextBox2.Value

Else ‘ I’ve tried this with and without Else part

' ***this section works fine if the top section is disabled***
If (TextBox2.Value) Range("Base_Pay").Value Then
Application.Goto Reference:="Account_1"
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.Value = TextBox1.Value
ActiveCell.Offset(0, 4).Select ‘Goes to Credit column
ActiveCell.Value = Range("Base_Pay").Value - TextBox2.Value

End If
End If

‘AllocatePay ‘ this is where it goes after performing routine above.
This works fine. I disabled this during testing.


End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
AutoSum not working correctly JimBUFF Excel Discussion (Misc queries) 2 November 9th 08 09:36 PM
Filters not working correctly EZ Setting up and Configuration of Excel 1 September 1st 08 05:15 PM
WorksheetFunction not working correctly Ayo Excel Discussion (Misc queries) 1 July 23rd 08 05:48 PM
Code not working correctly Zak Excel Programming 2 January 30th 08 02:28 PM
Formulas not working correctly Curt D. Excel Worksheet Functions 6 November 1st 07 08:48 PM


All times are GMT +1. The time now is 02:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"