ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Compile Error: Block If without End if (https://www.excelbanter.com/excel-programming/355027-compile-error-block-if-without-end-if.html)

[email protected]

Compile Error: Block If without End if
 
This is my first time using a Microsoft Excel Macro and I'm trying to
run the following code and keep getting the:

Compile Error: Block If without End if message and I can't figure out
why


Sub P()
'
' Macro1 Macro
' Changing FedEx Descriptions
'
' Keyboard Shortcut: Ctrl+Shift+X
'
If Range("K2:K999").Select = "02" Then


Range("M2:M999").Select = "FedEx Ground"
Else


If Range("K2:K999").Select = "03" Then
Range("M2:M999").Select = "FedEx 2Day"


Else


If Range("K2:K999").Select = "" Then
Range("M2:M999").Select = ""


End If
End Sub


Carim[_3_]

Compile Error: Block If without End if
 
Hi,

There is no need for a macro ...
just copy this formula from K2 to K999
=IF(K2="02","FedEx Ground",IF(K2="03","FedEx 2Day",""))

HTH
Cheers
Carim


BadgerMK[_7_]

Compile Error: Block If without End if
 

If Range("K2:K999").value = "02" Then
Range("M2:M999").value = "FedEx Ground"
ElseIf Range("K2:K999").Select = "03" Then
Range("M2:M999").value = "FedEx 2Day"
ElseIf Range("K2:K999").value = "" Then
Range("M2:M999").value = ""
End If


--
BadgerMK
------------------------------------------------------------------------
BadgerMK's Profile: http://www.excelforum.com/member.php...o&userid=31406
View this thread: http://www.excelforum.com/showthread...hreadid=518749


Ardus Petus

Compile Error: Block If without End if
 
This will compile correctly, but des not make much sense to me...
Can you explain what you're trying to do?

'-----------------------------------------------------
Sub P()
'
' Macro1 Macro
' Changing FedEx Descriptions
'
' Keyboard Shortcut: Ctrl+Shift+X
'
If Range("K2:K999").Select = "02" Then
Range("M2:M999").Select = "FedEx Ground"
ElseIf Range("K2:K999").Select = "03" Then
Range("M2:M999").Select = "FedEx 2Day"
ElseIf Range("K2:K999").Select = "" Then
Range("M2:M999").Select = ""
End If
End Sub

'-----------------------------------------------------
HTH
--
AP

a écrit dans le message de
oups.com...
This is my first time using a Microsoft Excel Macro and I'm trying to
run the following code and keep getting the:

Compile Error: Block If without End if message and I can't figure out
why


Sub P()
'
' Macro1 Macro
' Changing FedEx Descriptions
'
' Keyboard Shortcut: Ctrl+Shift+X
'
If Range("K2:K999").Select = "02" Then


Range("M2:M999").Select = "FedEx Ground"
Else


If Range("K2:K999").Select = "03" Then
Range("M2:M999").Select = "FedEx 2Day"


Else


If Range("K2:K999").Select = "" Then
Range("M2:M999").Select = ""


End If
End Sub




Chip Pearson

Compile Error: Block If without End if
 
You're missing and End If to pair up with the line

If Range("K2:K999").Select = "" Then

If you properly indent your code, missing End Ifs (and other End
statements like End With, End Select) are very easy to find. Get
into the habit of properly indenting your code.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



wrote in message
oups.com...
This is my first time using a Microsoft Excel Macro and I'm
trying to
run the following code and keep getting the:

Compile Error: Block If without End if message and I can't
figure out
why


Sub P()
'
' Macro1 Macro
' Changing FedEx Descriptions
'
' Keyboard Shortcut: Ctrl+Shift+X
'
If Range("K2:K999").Select = "02" Then


Range("M2:M999").Select = "FedEx Ground"
Else


If Range("K2:K999").Select = "03" Then
Range("M2:M999").Select = "FedEx 2Day"


Else


If Range("K2:K999").Select = "" Then
Range("M2:M999").Select = ""


End If
End Sub




Ardus Petus

Compile Error: Block If without End if
 
Thanks for your explanations.
This is no VBA job (too slow)
You'd rather enter the following formula into M2 et copy it down to M999:

=IF(K2=2;"FedEx Ground;IF(K2=3,"FedEx 2Day","")

HTH
--
AP

a écrit dans le message de
oups.com...
This is my first time using a Microsoft Excel Macro and I'm trying to
run the following code and keep getting the:

Compile Error: Block If without End if message and I can't figure out
why


Sub P()
'
' Macro1 Macro
' Changing FedEx Descriptions
'
' Keyboard Shortcut: Ctrl+Shift+X
'
If Range("K2:K999").Select = "02" Then


Range("M2:M999").Select = "FedEx Ground"
Else


If Range("K2:K999").Select = "03" Then
Range("M2:M999").Select = "FedEx 2Day"


Else


If Range("K2:K999").Select = "" Then
Range("M2:M999").Select = ""


End If
End Sub




Ardus Petus

Compile Error: Block If without End if
 
Thanks for your explanations.
This is no VBA job (too slow)
You'd rather enter the following formula into M2 et copy it down to M999:

=IF(K2=2;"FedEx Ground;IF(K2=3,"FedEx 2Day","")

HTH
--
AP

a écrit dans le message de
oups.com...
This is my first time using a Microsoft Excel Macro and I'm trying to
run the following code and keep getting the:

Compile Error: Block If without End if message and I can't figure out
why


Sub P()
'
' Macro1 Macro
' Changing FedEx Descriptions
'
' Keyboard Shortcut: Ctrl+Shift+X
'
If Range("K2:K999").Select = "02" Then


Range("M2:M999").Select = "FedEx Ground"
Else


If Range("K2:K999").Select = "03" Then
Range("M2:M999").Select = "FedEx 2Day"


Else


If Range("K2:K999").Select = "" Then
Range("M2:M999").Select = ""


End If
End Sub





Tom Ogilvy

Compile Error: Block If without End if
 
Range("M2:M999").Formula = "=IF(K2=2,""FedEx Ground"",IF(K2=3,""FedEx
2Day"","""")"

so combining the suggestion with VBA can often be very fast.

--
REgards,
Tom Ogilvy

"Ardus Petus" wrote in message
...
Thanks for your explanations.
This is no VBA job (too slow)
You'd rather enter the following formula into M2 et copy it down to M999:

=IF(K2=2;"FedEx Ground;IF(K2=3,"FedEx 2Day","")

HTH
--
AP

a écrit dans le message de
oups.com...
This is my first time using a Microsoft Excel Macro and I'm trying to
run the following code and keep getting the:

Compile Error: Block If without End if message and I can't figure out
why


Sub P()
'
' Macro1 Macro
' Changing FedEx Descriptions
'
' Keyboard Shortcut: Ctrl+Shift+X
'
If Range("K2:K999").Select = "02" Then


Range("M2:M999").Select = "FedEx Ground"
Else


If Range("K2:K999").Select = "03" Then
Range("M2:M999").Select = "FedEx 2Day"


Else


If Range("K2:K999").Select = "" Then
Range("M2:M999").Select = ""


End If
End Sub







Dave Peterson

Compile Error: Block If without End if
 
See one more post at your thread in .misc.

(Hi, Tom!)

wrote:

This is my first time using a Microsoft Excel Macro and I'm trying to
run the following code and keep getting the:

Compile Error: Block If without End if message and I can't figure out
why

Sub P()
'
' Macro1 Macro
' Changing FedEx Descriptions
'
' Keyboard Shortcut: Ctrl+Shift+X
'
If Range("K2:K999").Select = "02" Then

Range("M2:M999").Select = "FedEx Ground"
Else

If Range("K2:K999").Select = "03" Then
Range("M2:M999").Select = "FedEx 2Day"

Else

If Range("K2:K999").Select = "" Then
Range("M2:M999").Select = ""

End If
End Sub


--

Dave Peterson

Tom Ogilvy

Compile Error: Block If without End if
 
Say it ain't so; another bottom feeding multiposter? <g

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
See one more post at your thread in .misc.

(Hi, Tom!)

wrote:

This is my first time using a Microsoft Excel Macro and I'm trying to
run the following code and keep getting the:

Compile Error: Block If without End if message and I can't figure out
why

Sub P()
'
' Macro1 Macro
' Changing FedEx Descriptions
'
' Keyboard Shortcut: Ctrl+Shift+X
'
If Range("K2:K999").Select = "02" Then

Range("M2:M999").Select = "FedEx Ground"
Else

If Range("K2:K999").Select = "03" Then
Range("M2:M999").Select = "FedEx 2Day"

Else

If Range("K2:K999").Select = "" Then
Range("M2:M999").Select = ""

End If
End Sub


--

Dave Peterson




Dave Peterson

Compile Error: Block If without End if
 
I've chastised him properly in that other thread <vbg.

What's the difference between a multiposter and a catfish?

One is a bottom feeder; the other is a fish.

(or something like that with bosses/lawyers/etc....)

Tom Ogilvy wrote:

Say it ain't so; another bottom feeding multiposter? <g

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
See one more post at your thread in .misc.

(Hi, Tom!)

wrote:

This is my first time using a Microsoft Excel Macro and I'm trying to
run the following code and keep getting the:

Compile Error: Block If without End if message and I can't figure out
why

Sub P()
'
' Macro1 Macro
' Changing FedEx Descriptions
'
' Keyboard Shortcut: Ctrl+Shift+X
'
If Range("K2:K999").Select = "02" Then

Range("M2:M999").Select = "FedEx Ground"
Else

If Range("K2:K999").Select = "03" Then
Range("M2:M999").Select = "FedEx 2Day"

Else

If Range("K2:K999").Select = "" Then
Range("M2:M999").Select = ""

End If
End Sub


--

Dave Peterson


--

Dave Peterson

Tom Ogilvy

Compile Error: Block If without End if
 
I've chastised him properly in that other thread <vbg.

It's good to know the streets are safe again! We all owe you a debt of
graditude.
(faintly in the background: "Who was that masked man?" . . . "Why that
was the Loooone Ranger" . . . )


--
Regards,
Tom Ogilvy


"Dave Peterson" wrote in message
...
I've chastised him properly in that other thread <vbg.

What's the difference between a multiposter and a catfish?

One is a bottom feeder; the other is a fish.

(or something like that with bosses/lawyers/etc....)

Tom Ogilvy wrote:

Say it ain't so; another bottom feeding multiposter? <g

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
See one more post at your thread in .misc.

(Hi, Tom!)

wrote:

This is my first time using a Microsoft Excel Macro and I'm trying

to
run the following code and keep getting the:

Compile Error: Block If without End if message and I can't figure

out
why

Sub P()
'
' Macro1 Macro
' Changing FedEx Descriptions
'
' Keyboard Shortcut: Ctrl+Shift+X
'
If Range("K2:K999").Select = "02" Then

Range("M2:M999").Select = "FedEx Ground"
Else

If Range("K2:K999").Select = "03" Then
Range("M2:M999").Select = "FedEx 2Day"

Else

If Range("K2:K999").Select = "" Then
Range("M2:M999").Select = ""

End If
End Sub

--

Dave Peterson


--

Dave Peterson




Dave Peterson

Compile Error: Block If without End if
 
I prefer to think of myself more of the Jack Webb, er, Sgt. Joe Friday kind of
guy.

That should annoy the young and the non-USA centric.

Tom Ogilvy wrote:

I've chastised him properly in that other thread <vbg.


It's good to know the streets are safe again! We all owe you a debt of
graditude.
(faintly in the background: "Who was that masked man?" . . . "Why that
was the Loooone Ranger" . . . )

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
I've chastised him properly in that other thread <vbg.

What's the difference between a multiposter and a catfish?

One is a bottom feeder; the other is a fish.

(or something like that with bosses/lawyers/etc....)

Tom Ogilvy wrote:

Say it ain't so; another bottom feeding multiposter? <g

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
See one more post at your thread in .misc.

(Hi, Tom!)

wrote:

This is my first time using a Microsoft Excel Macro and I'm trying

to
run the following code and keep getting the:

Compile Error: Block If without End if message and I can't figure

out
why

Sub P()
'
' Macro1 Macro
' Changing FedEx Descriptions
'
' Keyboard Shortcut: Ctrl+Shift+X
'
If Range("K2:K999").Select = "02" Then

Range("M2:M999").Select = "FedEx Ground"
Else

If Range("K2:K999").Select = "03" Then
Range("M2:M999").Select = "FedEx 2Day"

Else

If Range("K2:K999").Select = "" Then
Range("M2:M999").Select = ""

End If
End Sub

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 05:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com