Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default change formula to code function

=IF(AND('Sheet One'!F16<""),'Sheet One'!F16+'Sheet Two'!F16,"")

The above formula is what i want to change to a code function.

I am not quite sure how to write this, especially when working with
references across different worksheets.

Any help appreciated

Regards

Corey


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default change formula to code function

Coey,

You have to refer to the worksheets and the ranges as

worksheets("Sheet One").Range("F16")
and
worksheets("Sheet Two").Range("F16")

therefore the formual is

if worksheets("Sheet One").Range("F16") < "" then
worksheets("???").Range("???") = _
worksheets("Sheet One").Range("F16") + _
worksheets("Sheet Two").Range("F16")
else
worksheets("???").Range("???") = ""
endif
' replace the ??? with the worksheet and cell where the ans goes.


it can also be done using a iif which is like the if in excel:

worksheets("???").Range("???") = _
iif(worksheets("Sheet One").Range("F16") < "", _
worksheets("Sheet One").Range("F16") + _
worksheets("Sheet Two").Range("F16"), _
"")

If you are using the references to worksheets a lot make a reference to the
worksheet:

dim ws1 as worksheet
dim ws2 as worksheet

set ws1= worksheets("Sheet One")
set ws2= worksheets("Sheet Two")
set wsans=worksheets("???")

wsans.range("???") = iif(ws1.Range("F16") < "", _
ws1.Range("F16") + ws2.Range("F16"), "")

--
HTHs Martin


"Corey" wrote:

=IF(AND('Sheet One'!F16<""),'Sheet One'!F16+'Sheet Two'!F16,"")

The above formula is what i want to change to a code function.

I am not quite sure how to write this, especially when working with
references across different worksheets.

Any help appreciated

Regards

Corey



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default change formula to code function


Your problem is with the AND that is not used.
Here it is as code:
Sub test()
Dim a As String
a = Chr(34)
Worksheets(2).Select
Cells(1, 1) = "=IF('Sheet One'!F16<" & a & a & ",'Shee
One'!F16+'Sheet Two'!F16," & a & a & ")"
End Su

--
raypayett

-----------------------------------------------------------------------
raypayette's Profile: http://www.excelforum.com/member.php...fo&userid=2956
View this thread: http://www.excelforum.com/showthread.php?threadid=57062

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
change SUMIF formula into a vb code ASU Excel Discussion (Misc queries) 1 September 6th 06 07:08 PM
Private Function Code Change Phil H[_2_] Excel Programming 5 April 14th 06 02:04 PM
change the code to be a formula Little pete Excel Discussion (Misc queries) 1 November 30th 05 07:29 PM
how change formula with this code? Ian Elliott Excel Programming 1 September 27th 05 06:49 PM
Help: Nested If/And Function formula to VB code RAP Excel Programming 2 August 9th 05 05:39 AM


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