Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default If-statement in Macro


My macro should check several cells (in the example below it's just one
D10) for their value and based on that, write a 0 or a 1 into cell B4
That works so fine so far (also I have some doubts on the type/forma
of the number written into B4). The value in B4 now should be used a
an argument in an if-statement (still in the macro). Doesn't work
Sometimes executes the 'if' and sometimes the 'else'...

Range("B4").Value = "=IF(D102,0,1)"

If Range("B4").Value = 1 Then
...
Else
...
End If

Any help appreciated, cheers

Fabaliciou

--
fabaliciou
-----------------------------------------------------------------------
fabalicious's Profile: http://www.excelforum.com/member.php...nfo&userid=807
View this thread: http://www.excelforum.com/showthread.php?threadid=26751

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default If-statement in Macro


Try this, it worked for me

Sub test()
Range("b4").Formula = "=IF(D102,0,1)"
If Range("B4").Value = 1 Then
MsgBox "The value of B4 is 1"
Else
MsgBox "The value of B4 is 0"
End If
End Sub

HTH
Terry

"fabalicious" wrote in message
...

My macro should check several cells (in the example below it's just one,
D10) for their value and based on that, write a 0 or a 1 into cell B4.
That works so fine so far (also I have some doubts on the type/format
of the number written into B4). The value in B4 now should be used as
an argument in an if-statement (still in the macro). Doesn't work!
Sometimes executes the 'if' and sometimes the 'else'...

Range("B4").Value = "=IF(D102,0,1)"

If Range("B4").Value = 1 Then
..
Else
..
End If

Any help appreciated, cheers

Fabalicious


--
fabalicious
------------------------------------------------------------------------
fabalicious's Profile:

http://www.excelforum.com/member.php...fo&userid=8072
View this thread: http://www.excelforum.com/showthread...hreadid=267514



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
Macro to If Statement JHusker Excel Discussion (Misc queries) 7 October 10th 08 10:39 PM
If Statement to run a macro Secret Squirrel Excel Discussion (Misc queries) 4 July 15th 08 03:43 PM
can i use an IF Statement to run a macro? Davidrowland88 Excel Worksheet Functions 2 February 11th 05 12:45 PM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM
use of Macro in If statement Tom Ogilvy Excel Programming 0 July 22nd 04 05:27 PM


All times are GMT +1. The time now is 04:19 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"