PC Review


Reply
Thread Tools Rate Thread

Compile error: End If without block IF

 
 
=?Utf-8?B?Q2FzZXk=?=
Guest
Posts: n/a
 
      28th Mar 2007
I can't seem to find why I'm getting this error. I have four If statements
and four End If statements. The error is hitting on the second "End If "
statement. Here is my Code:

Sub TransferToPO()
Dim rng1 As Range, rng2 As Range, rng3 As Range

Dim wks1 As Worksheet
Dim wks2 As Worksheet
Dim CopyRow3 As Long
Dim Entries As Long
Dim i As Long
Dim N As Variant
Dim Cnt As Long
Dim Cnt2 As Long
Dim Cnt3 As Long
Dim Msg As Integer
Dim Response As Integer

Msg = MsgBox("Have you selected the items you want exported?" _
& (Chr(13)) & "This will export all selected items to the " _
& " Purchase Order." _
& (Chr(13)) & "Are you ready to create a Purchase Order?", _
vbYesNo + vbQuestion, "Export to Purchase Order")
If Msg = 6 Then
Application.ScreenUpdating = False
Call Add_New_PO
Cnt = 0
Cnt3 = 0
Set wks1 = Worksheets("Materials Summary")
Set wks2 = Worksheets("Purchase Order")

Set rng1 = Range("TopRow1")
Set rng2 = Range("Below_Entry_Bottom_RowPO").Offset(-1)
Set rng1 = Intersect(rng1, rng1.Parent.Columns(1))
Set rng2 = Intersect(rng2, rng2.Parent.Columns(1))
Set rng3 = rng1.Parent.Range(rng1, rng2)
Cnt2 = rng3.SpecialCells(xlBlanks).Count
CopyRow3 = rng1.Row
Entries = Excel.WorksheetFunction.CountA(wks1.Range("A:A"))

For i = 8 To Entries + 100
N = wks1.Cells(i, 1).Value
If N = "X" Then Cnt = Cnt + 1
Cnt3 = Cnt2 - Cnt
If Cnt3 < 0 Then
Call InsertBlankLastRow_CheckIfBlank
With wks2
.Unprotect ("geekk")
.Cells(CopyRow3, 1).Value = wks1.Cells(i, 3).Value
.Cells(CopyRow3, 4).Value = wks1.Cells(i, 2).Value
.Cells(CopyRow3, 5).Value = wks1.Cells(i, 4).Value
.Protect ("geekk")
End With
CopyRow3 = CopyRow3 + 1
End If
End If
Next i

wks2.Range("E8").Activate
Application.ScreenUpdating = True
End If
If Msg = 7 Then
Exit Sub

End If
End Sub


--
Casey


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2FzZXk=?=
Guest
Posts: n/a
 
      28th Mar 2007
That was the problem thank you Stefi.
--
Casey




"Stefi" wrote:

> See comment in the code below!
> Regards,
> Stefi
>
>
> „Casey” ezt *rta:
>
> > I can't seem to find why I'm getting this error. I have four If statements
> > and four End If statements. The error is hitting on the second "End If "
> > statement. Here is my Code:
> >
> > Sub TransferToPO()
> > Dim rng1 As Range, rng2 As Range, rng3 As Range
> >
> > Dim wks1 As Worksheet
> > Dim wks2 As Worksheet
> > Dim CopyRow3 As Long
> > Dim Entries As Long
> > Dim i As Long
> > Dim N As Variant
> > Dim Cnt As Long
> > Dim Cnt2 As Long
> > Dim Cnt3 As Long
> > Dim Msg As Integer
> > Dim Response As Integer
> >
> > Msg = MsgBox("Have you selected the items you want exported?" _
> > & (Chr(13)) & "This will export all selected items to the " _
> > & " Purchase Order." _
> > & (Chr(13)) & "Are you ready to create a Purchase Order?", _
> > vbYesNo + vbQuestion, "Export to Purchase Order")
> > If Msg = 6 Then
> > Application.ScreenUpdating = False
> > Call Add_New_PO
> > Cnt = 0
> > Cnt3 = 0
> > Set wks1 = Worksheets("Materials Summary")
> > Set wks2 = Worksheets("Purchase Order")
> >
> > Set rng1 = Range("TopRow1")
> > Set rng2 = Range("Below_Entry_Bottom_RowPO").Offset(-1)
> > Set rng1 = Intersect(rng1, rng1.Parent.Columns(1))
> > Set rng2 = Intersect(rng2, rng2.Parent.Columns(1))
> > Set rng3 = rng1.Parent.Range(rng1, rng2)
> > Cnt2 = rng3.SpecialCells(xlBlanks).Count
> > CopyRow3 = rng1.Row
> > Entries = Excel.WorksheetFunction.CountA(wks1.Range("A:A"))
> >
> > For i = 8 To Entries + 100
> > N = wks1.Cells(i, 1).Value

>
> This is a complete IF line in itself which doesn't require an ENDIF, but
> still you gave it one (see below!)
>
>
> > If N = "X" Then Cnt = Cnt + 1

>
>
> > Cnt3 = Cnt2 - Cnt
> > If Cnt3 < 0 Then
> > Call InsertBlankLastRow_CheckIfBlank
> > With wks2
> > .Unprotect ("geekk")
> > .Cells(CopyRow3, 1).Value = wks1.Cells(i, 3).Value
> > .Cells(CopyRow3, 4).Value = wks1.Cells(i, 2).Value
> > .Cells(CopyRow3, 5).Value = wks1.Cells(i, 4).Value
> > .Protect ("geekk")
> > End With
> > CopyRow3 = CopyRow3 + 1
> > End If

>
>
> This is the redundant ENDIF
> > End If

>
>
> > Next i
> >
> > wks2.Range("E8").Activate
> > Application.ScreenUpdating = True
> > End If
> > If Msg = 7 Then
> > Exit Sub
> >
> > End If
> > End Sub
> >
> >
> > --
> > Casey
> >
> >

 
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
RE: Compile error: End If without block IF =?Utf-8?B?U3RlZmk=?= Microsoft Excel Programming 0 28th Mar 2007 01:09 AM
RE: Compile error: End If without block IF =?Utf-8?B?dXJrZWM=?= Microsoft Excel Programming 0 28th Mar 2007 12:21 AM
Compile Error: End if without block if. =?Utf-8?B?RUxD?= Microsoft Access Form Coding 3 6th Sep 2006 04:11 PM
Compile Error: Block If without End if blackmanofsteel40@gmail.com Microsoft Excel Misc 5 3rd Mar 2006 06:30 PM
compile error: block if without end if whelanj Microsoft Excel Programming 4 9th Jun 2004 07:32 PM


Features
 

Advertising
 

Newsgroups
 


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