Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Writing an IF/Then Statement in VB based on entry in a cell

I have defined the following value for a cell within my macro

Range("K" & i).Select
ActiveCell.FormulaR1C1 = _
"=((YEAR(RC[-1])-YEAR(RC[-2]))*12)+(MONTH(RC[-1])-MONTH(RC[-2]))"

If the value of this range is 0, I want to do other things. I'm not sure
how to write an "IF" statement to capture this information. How do I do
that?

Thanks in advance,
Barb Reinhardt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 222
Default Writing an IF/Then Statement in VB based on entry in a cell

Something like this perhaps:-

If ActiveCell.Value 0 Then
' put here what you want to happen i.e.
MsgBox "it's working!!"
End If

"Barb Reinhardt" wrote:

I have defined the following value for a cell within my macro

Range("K" & i).Select
ActiveCell.FormulaR1C1 = _
"=((YEAR(RC[-1])-YEAR(RC[-2]))*12)+(MONTH(RC[-1])-MONTH(RC[-2]))"

If the value of this range is 0, I want to do other things. I'm not sure
how to write an "IF" statement to capture this information. How do I do
that?

Thanks in advance,
Barb Reinhardt

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Writing an IF/Then Statement in VB based on entry in a cell

Range("K" & i).Activate
ActiveCell.FormulaR1C1 = _
"=((YEAR(RC[-1])-YEAR(RC[-2]))*12)+(MONTH(RC[-1])-MONTH(RC[-2]))"
ActiveCell.Value 0 Then
'do something
Else
'do something else
End If


Hutch
--------------------------------
"Barb Reinhardt" wrote:

I have defined the following value for a cell within my macro

Range("K" & i).Select
ActiveCell.FormulaR1C1 = _
"=((YEAR(RC[-1])-YEAR(RC[-2]))*12)+(MONTH(RC[-1])-MONTH(RC[-2]))"

If the value of this range is 0, I want to do other things. I'm not sure
how to write an "IF" statement to capture this information. How do I do
that?

Thanks in advance,
Barb Reinhardt

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Writing an IF/Then Statement in VB based on entry in a cell

Thanks. The ActiveCell.Value part was what I needed.

Now I have another question. How do I check to see If ActiveCell.Value =
#N/A. I can't seem to figure this one out.


"bigwheel" wrote:

Something like this perhaps:-

If ActiveCell.Value 0 Then
' put here what you want to happen i.e.
MsgBox "it's working!!"
End If

"Barb Reinhardt" wrote:

I have defined the following value for a cell within my macro

Range("K" & i).Select
ActiveCell.FormulaR1C1 = _
"=((YEAR(RC[-1])-YEAR(RC[-2]))*12)+(MONTH(RC[-1])-MONTH(RC[-2]))"

If the value of this range is 0, I want to do other things. I'm not sure
how to write an "IF" statement to capture this information. How do I do
that?

Thanks in advance,
Barb Reinhardt

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Writing an IF/Then Statement in VB based on entry in a cell

Barb,

Now I have another question. How do I check to see If
ActiveCell.Value =
#N/A. I can't seem to figure this one out.


Try

If Application.WorksheetFunction.IsNA(ActiveCell.Valu e) Then
Debug.Print "is n/a"
Else
Debug.Print "not n/a"
End If


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



"Barb Reinhardt" wrote
in message
...
Thanks. The ActiveCell.Value part was what I needed.

Now I have another question. How do I check to see If
ActiveCell.Value =
#N/A. I can't seem to figure this one out.


"bigwheel" wrote:

Something like this perhaps:-

If ActiveCell.Value 0 Then
' put here what you want to happen i.e.
MsgBox "it's working!!"
End If

"Barb Reinhardt" wrote:

I have defined the following value for a cell within my
macro

Range("K" & i).Select
ActiveCell.FormulaR1C1 = _

"=((YEAR(RC[-1])-YEAR(RC[-2]))*12)+(MONTH(RC[-1])-MONTH(RC[-2]))"

If the value of this range is 0, I want to do other
things. I'm not sure
how to write an "IF" statement to capture this information.
How do I do
that?

Thanks in advance,
Barb Reinhardt





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Writing an IF/Then Statement in VB based on entry in a cell

One more way:

if activecell.text = "#N/A" then



Barb Reinhardt wrote:

Thanks. The ActiveCell.Value part was what I needed.

Now I have another question. How do I check to see If ActiveCell.Value =
#N/A. I can't seem to figure this one out.

"bigwheel" wrote:

Something like this perhaps:-

If ActiveCell.Value 0 Then
' put here what you want to happen i.e.
MsgBox "it's working!!"
End If

"Barb Reinhardt" wrote:

I have defined the following value for a cell within my macro

Range("K" & i).Select
ActiveCell.FormulaR1C1 = _
"=((YEAR(RC[-1])-YEAR(RC[-2]))*12)+(MONTH(RC[-1])-MONTH(RC[-2]))"

If the value of this range is 0, I want to do other things. I'm not sure
how to write an "IF" statement to capture this information. How do I do
that?

Thanks in advance,
Barb Reinhardt


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Writing an IF/Then Statement in VB based on entry in a cell

How about if the cell value is #Value! ???

"Dave Peterson" wrote:

One more way:

if activecell.text = "#N/A" then



Barb Reinhardt wrote:

Thanks. The ActiveCell.Value part was what I needed.

Now I have another question. How do I check to see If ActiveCell.Value =
#N/A. I can't seem to figure this one out.

"bigwheel" wrote:

Something like this perhaps:-

If ActiveCell.Value 0 Then
' put here what you want to happen i.e.
MsgBox "it's working!!"
End If

"Barb Reinhardt" wrote:

I have defined the following value for a cell within my macro

Range("K" & i).Select
ActiveCell.FormulaR1C1 = _
"=((YEAR(RC[-1])-YEAR(RC[-2]))*12)+(MONTH(RC[-1])-MONTH(RC[-2]))"

If the value of this range is 0, I want to do other things. I'm not sure
how to write an "IF" statement to capture this information. How do I do
that?

Thanks in advance,
Barb Reinhardt


--

Dave Peterson

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Writing an IF/Then Statement in VB based on entry in a cell

if activecell.text = "#Value!" then

or

if iserror(activecell.value) then
to catch all kinds of errors



Barb Reinhardt wrote:

How about if the cell value is #Value! ???

"Dave Peterson" wrote:

One more way:

if activecell.text = "#N/A" then



Barb Reinhardt wrote:

Thanks. The ActiveCell.Value part was what I needed.

Now I have another question. How do I check to see If ActiveCell.Value =
#N/A. I can't seem to figure this one out.

"bigwheel" wrote:

Something like this perhaps:-

If ActiveCell.Value 0 Then
' put here what you want to happen i.e.
MsgBox "it's working!!"
End If

"Barb Reinhardt" wrote:

I have defined the following value for a cell within my macro

Range("K" & i).Select
ActiveCell.FormulaR1C1 = _
"=((YEAR(RC[-1])-YEAR(RC[-2]))*12)+(MONTH(RC[-1])-MONTH(RC[-2]))"

If the value of this range is 0, I want to do other things. I'm not sure
how to write an "IF" statement to capture this information. How do I do
that?

Thanks in advance,
Barb Reinhardt


--

Dave Peterson


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Writing an IF/Then Statement in VB based on entry in a cell

For some reason, it didn't work as I expected ... and then I realized I'd
goofed something else up. Thanks.

"Dave Peterson" wrote:

if activecell.text = "#Value!" then

or

if iserror(activecell.value) then
to catch all kinds of errors



Barb Reinhardt wrote:

How about if the cell value is #Value! ???

"Dave Peterson" wrote:

One more way:

if activecell.text = "#N/A" then



Barb Reinhardt wrote:

Thanks. The ActiveCell.Value part was what I needed.

Now I have another question. How do I check to see If ActiveCell.Value =
#N/A. I can't seem to figure this one out.

"bigwheel" wrote:

Something like this perhaps:-

If ActiveCell.Value 0 Then
' put here what you want to happen i.e.
MsgBox "it's working!!"
End If

"Barb Reinhardt" wrote:

I have defined the following value for a cell within my macro

Range("K" & i).Select
ActiveCell.FormulaR1C1 = _
"=((YEAR(RC[-1])-YEAR(RC[-2]))*12)+(MONTH(RC[-1])-MONTH(RC[-2]))"

If the value of this range is 0, I want to do other things. I'm not sure
how to write an "IF" statement to capture this information. How do I do
that?

Thanks in advance,
Barb Reinhardt

--

Dave Peterson


--

Dave Peterson

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
Force entry into cell, based on validation selection in adjacent cell Richhall[_2_] Excel Worksheet Functions 3 June 18th 09 10:28 AM
Writing a macro to hide columns based on cell value JAbels001 Excel Discussion (Misc queries) 2 April 16th 09 05:02 PM
Change Text Color in one cell based upon entry in referenced cell Tee Excel Discussion (Misc queries) 3 September 12th 08 10:07 PM
restricting entry into a cell based on entry to a previous cell newbie57 New Users to Excel 1 June 9th 08 05:43 PM
Input boxes - writing entry to cell Janet H[_2_] Excel Programming 2 August 1st 05 04:54 PM


All times are GMT +1. The time now is 05:29 AM.

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"