Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I use the "If" on many of my codes, But when I try to write "End If" after
the code, A message tell me that i can't "End If" without "Block If". Why? and Is there any reason to "End If" when the code works without? Thank You Aksel |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
it depends on how you write the IF statement a single line IF doesn't need an End IF e.g. IF Range("A1").value = 1 Then Exit Sub needs no End If (and doens't want one) however, if you write it as follows If Range("A1").value = 1 Then Exit Sub you need an End If (the code won't run without). hope this helps Cheers JulieD "aksel børve" wrote in message ... I use the "If" on many of my codes, But when I try to write "End If" after the code, A message tell me that i can't "End If" without "Block If". Why? and Is there any reason to "End If" when the code works without? Thank You Aksel |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
An 'End If' is required if you use 'block style' If/Then/Else
statements. For example, If whatever Then Debug.Print "yes" Else Debug.Print "no" End If An End If is not allowed if you use 'line style' If/Then/Else statements. For example, If whatever Then Debug.Print "yes" Else Debug.Print "no" What style of If statements are you using? -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "aksel børve" wrote in message ... I use the "If" on many of my codes, But when I try to write "End If" after the code, A message tell me that i can't "End If" without "Block If". Why? and Is there any reason to "End If" when the code works without? Thank You Aksel |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Alternatively, You can have another loop of some sort (e.g. While, Repeat, Select Case, etc.) crossing the if / end if statements. Bas Hartkamp. "aksel børve" wrote in message ... I use the "If" on many of my codes, But when I try to write "End If" after the code, A message tell me that i can't "End If" without "Block If". Why? and Is there any reason to "End If" when the code works without? Thank You Aksel |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"If" you have not already looked at it, the Excel help explanation on the
'If' statement is pretty good. Put your cursor on the word: If in your vba code and press F1 function key. "aksel børve" wrote: I use the "If" on many of my codes, But when I try to write "End If" after the code, A message tell me that i can't "End If" without "Block If". Why? and Is there any reason to "End If" when the code works without? Thank You Aksel |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|