ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If statement question (https://www.excelbanter.com/excel-programming/353312-if-statement-question.html)

dlb[_4_]

If statement question
 

I am making a macro to copy data from a cell in one workbook and pastin
it into another workbook. Unfortunatly I don't know VB too well, I'
more use to writing formulas in excel cells.

I'm trying to write an IF, THEN, ELSE statement in which the progra
will not display a cells contents if there is nothing to display (blan
cell). I do most of my programs in excel rather than VB. This is wha
I would put in excel to do what im looking to do: If(A1="","",A1).
How do I go about doing that in VB? Here is what I have so far, I'
just working around it by telling the program to display the results i
a different cell, but its not working as planned, and I need the progra
to just not display the info anywhere.

Dim NTHNG As String
Dim TFR1 As String

NTHNG = Range("GL19").Value
TFL1 = Range("BK12").Value

If TFL1 = "" Then .Cells(3, 115).Value = NTHNG Else .Cells(12
63).Value = TFL1

Any help would be appreciated

Da

--
dl
-----------------------------------------------------------------------
dlb's Profile: http://www.excelforum.com/member.php...fo&userid=1648
View this thread: http://www.excelforum.com/showthread.php?threadid=51243


Bob Phillips[_6_]

If statement question
 
Does this not work?


If TFL1 = "" Then
.Cells(3, 115).Value = Range("GL19").Value
Else
.Cells(12,63).Value = Range("BK12").Value
End If

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"dlb" wrote in message
...

I am making a macro to copy data from a cell in one workbook and pasting
it into another workbook. Unfortunatly I don't know VB too well, I'm
more use to writing formulas in excel cells.

I'm trying to write an IF, THEN, ELSE statement in which the program
will not display a cells contents if there is nothing to display (blank
cell). I do most of my programs in excel rather than VB. This is what
I would put in excel to do what im looking to do: If(A1="","",A1).
How do I go about doing that in VB? Here is what I have so far, I'm
just working around it by telling the program to display the results in
a different cell, but its not working as planned, and I need the program
to just not display the info anywhere.

Dim NTHNG As String
Dim TFR1 As String

NTHNG = Range("GL19").Value
TFL1 = Range("BK12").Value

If TFL1 = "" Then .Cells(3, 115).Value = NTHNG Else .Cells(12,
63).Value = TFL1

Any help would be appreciated

Dan


--
dlb
------------------------------------------------------------------------
dlb's Profile:

http://www.excelforum.com/member.php...o&userid=16483
View this thread: http://www.excelforum.com/showthread...hreadid=512432




dlb[_5_]

If statement question
 

The NTHNG cell has an "X" in it, even if I keep the cell blank, it won't
work. The workbook I'm pasting into is protected, but the cell is
unprotected, and that cell is referenced in a formula that can only
read numbers, or blank cells, and for some reason even if I paste a
blank cell into it, it reads that as something rather than nothing, and
it causes an error in the formula.

Basically I'm trying to find out how to write an IF statement that will
not do anything if the cell is blank. Is that possible? Or is there
another way of doing this?

Dan


--
dlb
------------------------------------------------------------------------
dlb's Profile: http://www.excelforum.com/member.php...o&userid=16483
View this thread: http://www.excelforum.com/showthread...hreadid=512432


dlb[_6_]

If statement question
 

still having some troubles w/ this


--
dlb
------------------------------------------------------------------------
dlb's Profile: http://www.excelforum.com/member.php...o&userid=16483
View this thread: http://www.excelforum.com/showthread...hreadid=512432


dlb[_7_]

If statement question
 

any ideas

--
dl
-----------------------------------------------------------------------
dlb's Profile: http://www.excelforum.com/member.php...fo&userid=1648
View this thread: http://www.excelforum.com/showthread.php?threadid=51243


Amber_D_Laws[_86_]

If statement question
 

It seems to me that Bob gave you a good start, but if I am reading what
you are asking right, I thing the code might be more like this:


Code:
--------------------
If TFL1 = "" Then
'do nothing
Else
'insert the code for whatever it is you want it to do if there is something.
--------------------


Of course I am a little unclear as to what you are actually trying to
accomplish, but then again that is not uncommon around here.

I don't know if that will help you at all, but whenever I am using an
IF statement in code, and one of the options of the if is when I want
it to do nothing, I just stick in the comment line " 'do nothing"
instead of trying to code for contingencies I can't even possibly guess
at.

Here's to hope, and take care,
Amber :)

Bob Phillips Wrote:
Does this not work?


If TFL1 = "" Then
.Cells(3, 115).Value = Range("GL19").Value
Else
.Cells(12,63).Value = Range("BK12").Value
End If

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"dlb" wrote in
message
...

I am making a macro to copy data from a cell in one workbook and

pasting
it into another workbook. Unfortunatly I don't know VB too well,

I'm
more use to writing formulas in excel cells.

I'm trying to write an IF, THEN, ELSE statement in which the program
will not display a cells contents if there is nothing to display

(blank
cell). I do most of my programs in excel rather than VB. This is

what
I would put in excel to do what im looking to do: If(A1="","",A1).
How do I go about doing that in VB? Here is what I have so far, I'm
just working around it by telling the program to display the results

in
a different cell, but its not working as planned, and I need the

program
to just not display the info anywhere.

Dim NTHNG As String
Dim TFR1 As String

NTHNG = Range("GL19").Value
TFL1 = Range("BK12").Value

If TFL1 = "" Then .Cells(3, 115).Value = NTHNG Else .Cells(12,
63).Value = TFL1

Any help would be appreciated

Dan


--
dlb

------------------------------------------------------------------------
dlb's Profile:

http://www.excelforum.com/member.php...o&userid=16483
View this thread:

http://www.excelforum.com/showthread...hreadid=512432



--
Amber_D_Laws
------------------------------------------------------------------------
Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
View this thread: http://www.excelforum.com/showthread...hreadid=512432



All times are GMT +1. The time now is 11:58 PM.

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