Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default end if without block if error

When this code is run i get the end if without block if error, but i
don't see what i am doing wrong. It highlights the very first "if"
statement

Private Sub btnSubmit_Click()



Sheets("rewards tracker").Activate


If Left(cmbDate.Value, 3) = "Sun" Then For i = 1 To txtQty.Value Step
1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(3) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Mon" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(8) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Tue" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(13) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Wed" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(18) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Thu" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(3) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Fri" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(8) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Sat" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(13) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

End If

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default end if without block if error

VBA has two different forms of the If-Then statement...

First Form
===============
If <Logical Then <Code

Second Form
===============
If <Logical Then
<Code
End If

and you cannot mix them. You have mixed them. Your opening If statement (you
also do this in your ElseIf statement)...

If Left(cmbDate.Value, 3) = "Sun" Then For i = 1 To txtQty.Value Step 1

contains <Code after the Then statement... there can be no linked ElseIf
nor End If statements with it. VBA assumes everything after your opening If
statement is independent lines of code... it is therefore choking on the
Next statements below it. Just move your For-Next statement out of the
If-Then single line statement and put it on its own line immediately below
the If-Then statement...

If Left(cmbDate.Value, 3) = "Sun" Then
For i = 1 To txtQty.Value Step
<<rest of your code

and do the same for the ElseIf statement also.

Rick



"stewart" wrote in message
ups.com...
When this code is run i get the end if without block if error, but i
don't see what i am doing wrong. It highlights the very first "if"
statement

Private Sub btnSubmit_Click()



Sheets("rewards tracker").Activate


If Left(cmbDate.Value, 3) = "Sun" Then For i = 1 To txtQty.Value Step
1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(3) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Mon" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(8) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Tue" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(13) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Wed" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(18) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Thu" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(3) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Fri" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(8) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Sat" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(13) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

End If

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default end if without block if error

On Sep 16, 11:46 am, "Rick Rothstein \(MVP - VB\)"
wrote:
VBA has two different forms of the If-Then statement...

First Form
===============
If <Logical Then <Code

Second Form
===============
If <Logical Then
<Code
End If

and you cannot mix them. You have mixed them. Your opening If statement (you
also do this in your ElseIf statement)...

If Left(cmbDate.Value, 3) = "Sun" Then For i = 1 To txtQty.Value Step 1

contains <Code after the Then statement... there can be no linked ElseIf
nor End If statements with it. VBA assumes everything after your opening If
statement is independent lines of code... it is therefore choking on the
Next statements below it. Just move your For-Next statement out of the
If-Then single line statement and put it on its own line immediately below
the If-Then statement...

If Left(cmbDate.Value, 3) = "Sun" Then
For i = 1 To txtQty.Value Step
<<rest of your code

and do the same for the ElseIf statement also.

Rick

"stewart" wrote in message

ups.com...

When this code is run i get the end if without block if error, but i
don't see what i am doing wrong. It highlights the very first "if"
statement


Private Sub btnSubmit_Click()


Sheets("rewards tracker").Activate


If Left(cmbDate.Value, 3) = "Sun" Then For i = 1 To txtQty.Value Step
1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(3) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i


ElseIf Left(cmbDate.Value, 3) = "Mon" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(8) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i


ElseIf Left(cmbDate.Value, 3) = "Tue" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(13) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i


ElseIf Left(cmbDate.Value, 3) = "Wed" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(18) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i


ElseIf Left(cmbDate.Value, 3) = "Thu" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(3) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i


ElseIf Left(cmbDate.Value, 3) = "Fri" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(8) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i


ElseIf Left(cmbDate.Value, 3) = "Sat" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(13) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i


End If


End Sub


That did the trick. Thanks, especially for explaining it. It really
helps.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default end if without block if error

It appears that there is only one variable so try this

Sub chooseday()
Select Case UCase(Left(Range("k3"), 3))
Case "THU": x = 3
Case "MON", "THU": x = 8
Case "TUE", "SAT": x = 13
Case "WED": x = 18
Case Else
End Select
'MsgBox x

For i = 1 To txtQty.Value
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
'variable on below line
Selection.Cells(x) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i
End Sub

This can and probably should be further refined to REMOVE the selections if
NOT needed. Maybe??

Sub chooseday1()
Select Case UCase(Left(Range("k3"), 3))
Case "THU": x = 3
Case "MON", "THU": x = 8
Case "TUE", "SAT": x = 13
Case "WED": x = 18
Case Else
End Select
'MsgBox x

For i = 1 To txtQty.Value
txtholder.Value = Me.Controls("txtNum" & i)
With Rows(txtholder.Value + 4)
.Cells(x) = Me.Controls("txtRew" & i)
.Offset(0, 1) = Me.Controls("txtTot" & i)
.Offset(0, 3) = Me.Controls("txtNew" & i).Value
End With
Next i
End Sub
==============
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"stewart" wrote in message
ups.com...
When this code is run i get the end if without block if error, but i
don't see what i am doing wrong. It highlights the very first "if"
statement

Private Sub btnSubmit_Click()



Sheets("rewards tracker").Activate


If Left(cmbDate.Value, 3) = "Sun" Then For i = 1 To txtQty.Value Step
1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(3) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Mon" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(8) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Tue" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(13) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Wed" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(18) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Thu" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(3) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Fri" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(8) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

ElseIf Left(cmbDate.Value, 3) = "Sat" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(13) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i

End If

End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default end if without block if error

On Sep 16, 12:21 pm, "Don Guillett" wrote:
It appears that there is only one variable so try this

Sub chooseday()
Select Case UCase(Left(Range("k3"), 3))
Case "THU": x = 3
Case "MON", "THU": x = 8
Case "TUE", "SAT": x = 13
Case "WED": x = 18
Case Else
End Select
'MsgBox x

For i = 1 To txtQty.Value
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
'variable on below line
Selection.Cells(x) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i
End Sub

This can and probably should be further refined to REMOVE the selections if
NOT needed. Maybe??

Sub chooseday1()
Select Case UCase(Left(Range("k3"), 3))
Case "THU": x = 3
Case "MON", "THU": x = 8
Case "TUE", "SAT": x = 13
Case "WED": x = 18
Case Else
End Select
'MsgBox x

For i = 1 To txtQty.Value
txtholder.Value = Me.Controls("txtNum" & i)
With Rows(txtholder.Value + 4)
.Cells(x) = Me.Controls("txtRew" & i)
.Offset(0, 1) = Me.Controls("txtTot" & i)
.Offset(0, 3) = Me.Controls("txtNew" & i).Value
End With
Next i
End Sub
==============
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"stewart" wrote in message

ups.com...

When this code is run i get the end if without block if error, but i
don't see what i am doing wrong. It highlights the very first "if"
statement


Private Sub btnSubmit_Click()


Sheets("rewards tracker").Activate


If Left(cmbDate.Value, 3) = "Sun" Then For i = 1 To txtQty.Value Step
1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(3) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i


ElseIf Left(cmbDate.Value, 3) = "Mon" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(8) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i


ElseIf Left(cmbDate.Value, 3) = "Tue" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(13) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i


ElseIf Left(cmbDate.Value, 3) = "Wed" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 4).Select
Selection.Cells(18) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i


ElseIf Left(cmbDate.Value, 3) = "Thu" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(3) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i


ElseIf Left(cmbDate.Value, 3) = "Fri" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(8) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i


ElseIf Left(cmbDate.Value, 3) = "Sat" Then For i = 1 To txtQty.Value
Step 1
txtholder.Value = Me.Controls("txtNum" & i).Value
Rows(txtholder.Value + 108).Select
Selection.Cells(13) = Me.Controls("txtRew" & i).Value
ActiveCell.Offset(0, 1) = Me.Controls("txtTot" & i).Value
ActiveCell.Offset(0, 3) = Me.Controls("txtNew" & i).Value
Next i


End If


End Sub


thank you. I was just working on condensing the code and this really
helped.

Reply
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
End If without Block If Error Help Bull Excel Programming 6 April 30th 07 08:24 PM
Compile error: End If without block IF Stefi Excel Programming 1 March 28th 07 01:09 AM
VBA error - End If without Block If Jane Excel Worksheet Functions 2 December 6th 05 06:00 PM
Error - End If Without Block Gauthier[_2_] Excel Programming 6 September 26th 04 05:14 AM
Error 91, Object var or With block not set Walter Excel Programming 2 August 24th 04 12:37 AM


All times are GMT +1. The time now is 09:31 PM.

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

About Us

"It's about Microsoft Excel"