LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default A Function puzzle


The following sub works OK when called from a subroutine as shown.

Sub CopyCyclic(num)
Range("a1") = "Q1"
Range("a2") = "Q2"
Range("a3") = "Q3"
Range("a4") = "Q4"
k = 0
For Each c In Range("a5:a500")
If c.Offset(1, 0) = "" Then
c.Value = c.Offset(-4, 0).Value
c.Offset(0, 1).Value = num
k = k + 1
If k Mod 4 = 0 Then num = num + 1
End If
Next
End Sub

Sub test()
[a:a].Clear
CopyCyclic (1980)

However, its function equivalent fails.

Function CopyCyclic(num)
Range("a1") = "Q1"
Range("a2") = "Q2"
Range("a3") = "Q3"
Range("a4") = "Q4"
k = 0
For Each c In Range("a5:a500")
If c.Offset(1, 0) = "" Then
c.Value = c.Offset(-4, 0).Value
c.Offset(0, 1).Value = num
k = k + 1
If k Mod 4 = 0 Then num = num + 1
End If
Next

Next
End Function

Entering *=CopyCyclic (1970*), for example, returns an error? An
error equally results if it is entered as array (Ctr+Shft+Ent) . Just
curious for an explanation.


--
davidm
------------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=387931

 
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
Excel Puzzle Templar Excel Discussion (Misc queries) 5 March 2nd 08 04:49 AM
vlookup puzzle lloyd Excel Worksheet Functions 3 December 6th 07 07:45 PM
Excel Puzzle dwalesb Excel Worksheet Functions 2 January 26th 06 06:27 PM
Can you help!!!!! New Puzzle Krefty Excel Discussion (Misc queries) 0 June 13th 05 08:13 PM
Randbetween puzzle??!? getexel Excel Programming 1 April 29th 04 06:30 PM


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