ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   If then help. (https://www.excelbanter.com/excel-discussion-misc-queries/205018-if-then-help.html)

JHB

If then help.
 
I have created the following macro, which appears fine to me but does
not run:

Sub setlowest()
'
' setlowest Macro
' Macro recorded 10/3/2008 by John
'
Sheets("Menu").Select


If Range("D33").Value Range("d42").ValueThen Then GoTo getout
Else
Range("D33").Select
Selection.Copy
Range("D42").Select
ActiveSheet.Paste
Range("C33").Select
Application.CutCopyMode = False
Selection.Copy
Range("E42").Select
ActiveSheet.Paste
End If
getout:
End Sub


I am told that there is an "else, but no If". I can see the if, and
have no idea what the issue is. Could someone tell me the
simple..stupid mistake that I am making, please?

Thanks in advance


Thomas [PBD]

If then help.
 
JHB,

Amended, you had an extra THEN and the GOTO needed to be on a separate line:

Sub setlowest()
'
' setlowest Macro
' Macro recorded 10/3/2008 by John
'
Sheets("Menu").Select


If Range("D33").Value Range("d42").Value Then
GoTo getout
Else
Range("D33").Select
Selection.Copy
Range("D42").Select
ActiveSheet.Paste
Range("C33").Select
Application.CutCopyMode = False
Selection.Copy
Range("E42").Select
ActiveSheet.Paste
End If
getout:
End Sub

--
--Thomas [PBD]
Working hard to make working easy.
Answered your question? Click ''Yes'' below.


"JHB" wrote:

I have created the following macro, which appears fine to me but does
not run:

Sub setlowest()
'
' setlowest Macro
' Macro recorded 10/3/2008 by John
'
Sheets("Menu").Select


If Range("D33").Value Range("d42").ValueThen Then GoTo getout
Else
Range("D33").Select
Selection.Copy
Range("D42").Select
ActiveSheet.Paste
Range("C33").Select
Application.CutCopyMode = False
Selection.Copy
Range("E42").Select
ActiveSheet.Paste
End If
getout:
End Sub


I am told that there is an "else, but no If". I can see the if, and
have no idea what the issue is. Could someone tell me the
simple..stupid mistake that I am making, please?

Thanks in advance



JHB

If then help.
 
On Oct 3, 5:04*pm, Thomas [PBD]
wrote:
JHB,

Amended, you had an extra THEN and the GOTO needed to be on a separate line:

Sub setlowest()
'
' setlowest Macro
' Macro recorded 10/3/2008 by John
'
Sheets("Menu").Select

If Range("D33").Value Range("d42").Value Then
GoTo getout
Else
* * Range("D33").Select
* * Selection.Copy
* * Range("D42").Select
* * ActiveSheet.Paste
* * Range("C33").Select
* * Application.CutCopyMode = False
* * Selection.Copy
* * Range("E42").Select
* * ActiveSheet.Paste
End If
getout:
End Sub

--
--Thomas [PBD]
Working hard to make working easy.
Answered your question? Click ''Yes'' below.

"JHB" wrote:
I have created the following macro, which appears fine to me but does
not run:


Sub setlowest()
'
' setlowest Macro
' Macro recorded 10/3/2008 by John
'
Sheets("Menu").Select


If Range("D33").Value Range("d42").ValueThen Then GoTo getout
Else
* * Range("D33").Select
* * Selection.Copy
* * Range("D42").Select
* * ActiveSheet.Paste
* * Range("C33").Select
* * Application.CutCopyMode = False
* * Selection.Copy
* * Range("E42").Select
* * ActiveSheet.Paste
End If
getout:
End Sub


I am told that there is an "else, but no If". I can see the if, and
have no idea what the issue is. Could someone tell me the
simple..stupid mistake that I am making, please?


Thanks in advance


Thank you very much. I knew it was some stupid thing that I had missed
-- I wont make that mistake again!


T. Valko

If then help.
 
You can reduce that further to:

Sub setlowest()

Sheets("Menu").Activate
If Range("D33").Value Range("d42").Value Then Exit Sub
Range("D42") = Range("D33").Value
Range("E42") = Range("C33").Value
End Sub

--
Biff
Microsoft Excel MVP


"JHB" wrote in message
...
On Oct 3, 5:04 pm, Thomas [PBD]
wrote:
JHB,

Amended, you had an extra THEN and the GOTO needed to be on a separate
line:

Sub setlowest()
'
' setlowest Macro
' Macro recorded 10/3/2008 by John
'
Sheets("Menu").Select

If Range("D33").Value Range("d42").Value Then
GoTo getout
Else
Range("D33").Select
Selection.Copy
Range("D42").Select
ActiveSheet.Paste
Range("C33").Select
Application.CutCopyMode = False
Selection.Copy
Range("E42").Select
ActiveSheet.Paste
End If
getout:
End Sub

--
--Thomas [PBD]
Working hard to make working easy.
Answered your question? Click ''Yes'' below.

"JHB" wrote:
I have created the following macro, which appears fine to me but does
not run:


Sub setlowest()
'
' setlowest Macro
' Macro recorded 10/3/2008 by John
'
Sheets("Menu").Select


If Range("D33").Value Range("d42").ValueThen Then GoTo getout
Else
Range("D33").Select
Selection.Copy
Range("D42").Select
ActiveSheet.Paste
Range("C33").Select
Application.CutCopyMode = False
Selection.Copy
Range("E42").Select
ActiveSheet.Paste
End If
getout:
End Sub


I am told that there is an "else, but no If". I can see the if, and
have no idea what the issue is. Could someone tell me the
simple..stupid mistake that I am making, please?


Thanks in advance


Thank you very much. I knew it was some stupid thing that I had missed
-- I wont make that mistake again!




All times are GMT +1. The time now is 06:39 PM.

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