Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Old February 28th 06, 05:16 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Dec 2005
Posts: 54
Default I'm trying to do a comparison if statement but it is not working!!

I'm trying to do a comparison operator that is being printed on an export
text file. What I am trying to do is this. See below:

1) If columns N and M in the worksheet have data, then I want them both
stored into a string variable and then it is to be exported onto a text file.
2) If column N has data and column M is null, then only N is to be stored
into a text string variable and then it is to be exported onto a text file.
3) If column M has data and column N is null, then only column M is to be
stored into a text string variable and then it is to be exported onto a text
file.
4) If columns N and M are null, then nothing is to be stored into the text
string and the line will be skipped on the text file that is to be exported
from Excel.

Everything works fine and the text file displays both of the fields properly
when they both have data, but if one of the columns is blank, then nothing
shows up on the text file. Why is this happening? Below is my logic for the
code, please see below.



If IsEmpty(Cells(I, "N").Value) Or Cells(I, "N").Value = "" Then
NVariable = ""
Else: NVariable = Cells(I, "N").Value
End If

If IsEmpty(Cells(I, "M").Value) Or Cells(I, "M").Value = "" Then
MVariable = ""
Else: MVariable = Cells(I, "M").Value
End If



NandMVariable = NVariable + MVariable

If IsEmpty(NandMVariable) Or NandMVariable = "" Then
NANDMVARSTRING = ""
ElseIf (NVariable = "" And MVariable < "") Then
NANDMVARSTRING = "$DATUM " & MVariable & vbCrLf
ElseIf (MVariable = "" And NVariable < "") Then
NANDMVARSTRING = "$DATUM " & NVariable & vbCrLf
ElseIf NandMVariable < "" Then
NANDMVARSTRING = "$DATUM " & NVariable & "_" & MVariable &
vbCrLf
End If

  #2   Report Post  
Old February 28th 06, 06:01 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Dec 2005
Posts: 54
Default I'm trying to do a comparison if statement but it is not working!!

Anybody have any thoughts as to why a simple comparision operator is not
working for me? Thanks!

"Brett Smith" wrote:

I'm trying to do a comparison operator that is being printed on an export
text file. What I am trying to do is this. See below:

1) If columns N and M in the worksheet have data, then I want them both
stored into a string variable and then it is to be exported onto a text file.
2) If column N has data and column M is null, then only N is to be stored
into a text string variable and then it is to be exported onto a text file.
3) If column M has data and column N is null, then only column M is to be
stored into a text string variable and then it is to be exported onto a text
file.
4) If columns N and M are null, then nothing is to be stored into the text
string and the line will be skipped on the text file that is to be exported
from Excel.

Everything works fine and the text file displays both of the fields properly
when they both have data, but if one of the columns is blank, then nothing
shows up on the text file. Why is this happening? Below is my logic for the
code, please see below.



If IsEmpty(Cells(I, "N").Value) Or Cells(I, "N").Value = "" Then
NVariable = ""
Else: NVariable = Cells(I, "N").Value
End If

If IsEmpty(Cells(I, "M").Value) Or Cells(I, "M").Value = "" Then
MVariable = ""
Else: MVariable = Cells(I, "M").Value
End If



NandMVariable = NVariable + MVariable

If IsEmpty(NandMVariable) Or NandMVariable = "" Then
NANDMVARSTRING = ""
ElseIf (NVariable = "" And MVariable < "") Then
NANDMVARSTRING = "$DATUM " & MVariable & vbCrLf
ElseIf (MVariable = "" And NVariable < "") Then
NANDMVARSTRING = "$DATUM " & NVariable & vbCrLf
ElseIf NandMVariable < "" Then
NANDMVARSTRING = "$DATUM " & NVariable & "_" & MVariable &
vbCrLf
End If

  #3   Report Post  
Old February 28th 06, 06:21 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 4,624
Default I'm trying to do a comparison if statement but it is not working!!

First, since you make an assignment to NandMVariable, it should never be
empty, so

IsEmpty(NandMVariable)

should always return false.

Second, since you're using the + operator, but not getting a Type
mismatch error, I assume your data in N and M is text. If that's the
case, I'd recommend using the & operator.

The only way I got your results was to have numeric data in one cell,
the other cell blank (or text) and have an On Error Resume Next
statement operative. Since that ignores the type mismatch error, no
assignment will be made to NandMVariable so the first IsEmpty() will
return true, and NANDMVARSTRING will be the null string.

However, it appears to me that your routine could be substituted by
something like

NandMString = ""
With Cells(I, "M").Resize(1, 2)
If Len(.Item(1).Text) + Len(.Item(2).Text) Then
NandMString = "$DATUM " & .Item(1).Text & _
IIf(Len(.Item(1).Text) And Len(.Item(2).Text), "_", "") & _
.Item(2).Text & vbCrLf
End If
End With


In article ,
"Brett Smith" wrote:


Everything works fine and the text file displays both of the fields properly
when they both have data, but if one of the columns is blank, then nothing
shows up on the text file. Why is this happening? Below is my logic for the
code, please see below.

  #4   Report Post  
Old February 28th 06, 06:36 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 27,285
Default I'm trying to do a comparison if statement but it is not working!!

Try changing

NandMVariable = NVariable + MVariable

to

NandMVariable = NVariable & MVariable

--
Regards,
Tom Ogilvy

"Brett Smith" wrote in message
...
I'm trying to do a comparison operator that is being printed on an export
text file. What I am trying to do is this. See below:

1) If columns N and M in the worksheet have data, then I want them both
stored into a string variable and then it is to be exported onto a text

file.
2) If column N has data and column M is null, then only N is to be stored
into a text string variable and then it is to be exported onto a text

file.
3) If column M has data and column N is null, then only column M is to be
stored into a text string variable and then it is to be exported onto a

text
file.
4) If columns N and M are null, then nothing is to be stored into the text
string and the line will be skipped on the text file that is to be

exported
from Excel.

Everything works fine and the text file displays both of the fields

properly
when they both have data, but if one of the columns is blank, then nothing
shows up on the text file. Why is this happening? Below is my logic for

the
code, please see below.



If IsEmpty(Cells(I, "N").Value) Or Cells(I, "N").Value = "" Then
NVariable = ""
Else: NVariable = Cells(I, "N").Value
End If

If IsEmpty(Cells(I, "M").Value) Or Cells(I, "M").Value = ""

Then
MVariable = ""
Else: MVariable = Cells(I, "M").Value
End If



NandMVariable = NVariable + MVariable

If IsEmpty(NandMVariable) Or NandMVariable = "" Then
NANDMVARSTRING = ""
ElseIf (NVariable = "" And MVariable < "") Then
NANDMVARSTRING = "$DATUM " & MVariable & vbCrLf
ElseIf (MVariable = "" And NVariable < "") Then
NANDMVARSTRING = "$DATUM " & NVariable & vbCrLf
ElseIf NandMVariable < "" Then
NANDMVARSTRING = "$DATUM " & NVariable & "_" & MVariable &
vbCrLf
End If



  #5   Report Post  
Old February 28th 06, 07:52 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Dec 2005
Posts: 54
Default I'm trying to do a comparison if statement but it is not worki

Thank you very much JE McGimpsey, you were very helpful!

"JE McGimpsey" wrote:

First, since you make an assignment to NandMVariable, it should never be
empty, so

IsEmpty(NandMVariable)

should always return false.

Second, since you're using the + operator, but not getting a Type
mismatch error, I assume your data in N and M is text. If that's the
case, I'd recommend using the & operator.

The only way I got your results was to have numeric data in one cell,
the other cell blank (or text) and have an On Error Resume Next
statement operative. Since that ignores the type mismatch error, no
assignment will be made to NandMVariable so the first IsEmpty() will
return true, and NANDMVARSTRING will be the null string.

However, it appears to me that your routine could be substituted by
something like

NandMString = ""
With Cells(I, "M").Resize(1, 2)
If Len(.Item(1).Text) + Len(.Item(2).Text) Then
NandMString = "$DATUM " & .Item(1).Text & _
IIf(Len(.Item(1).Text) And Len(.Item(2).Text), "_", "") & _
.Item(2).Text & vbCrLf
End If
End With


In article ,
"Brett Smith" wrote:


Everything works fine and the text file displays both of the fields properly
when they both have data, but if one of the columns is blank, then nothing
shows up on the text file. Why is this happening? Below is my logic for the
code, please see below.




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
IF Statement not working Barrett M Excel Worksheet Functions 8 May 6th 08 03:29 PM
HELP: Comparison IF statement R Weeden Excel Worksheet Functions 6 February 6th 06 09:55 PM
Date Comparison and IF statement Holly Excel Worksheet Functions 4 January 19th 06 02:01 AM
If statement not working excelnut1954 Excel Programming 6 December 15th 05 10:38 PM
Comparison Operators for IF statement. Shams Excel Worksheet Functions 1 February 14th 05 04:35 PM


All times are GMT +1. The time now is 12:18 AM.

Powered by vBulletin® Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright 2004-2021 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"

 

Copyright © 2017