+ Reply to Thread
Results 1 to 3 of 3

[Urgent] Problems about looping in the following program

  1. #1
    Registered User
    Join Date
    06-08-2015
    Location
    HK
    MS-Off Ver
    365
    Posts
    4

    [Urgent] Problems about looping in the following program

    Hi all,

    I am quite new to excel VBA programming, but I need to write a program to extract the month from the string "15w24" where "15" represents year 2015 and "24" represents the 24th week, starting from the first week of January (where first week of January in 2015 is represented as 15w01), I have two buttons, the first button is called commandbutton1, where once click it should convert the 15w24 into 6 (because 24th week is in June, just say) and the second button is called commandbutton2, where once click, it should extract 15(that's the year) from 15w24, and the aim is to once click these two buttons, all data from the row of 8, column AN should be stored in AO column (for month) and AP column(for year), here is my program:

    Please Login or Register  to view this content.


    It stuck into a loop, and please help me to solve the problem, it's quite urgent
    Thank you so much!
    Last edited by JBeaucaire; 06-08-2015 at 10:48 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

  2. #2
    Registered User
    Join Date
    11-13-2006
    Posts
    87

    Re: [Urgent] Problems about looping in the following program

    Range("AO" & CStr(k)) = MonthFromDt
    Same as Range("AO" & CStr(k)) = Call MonthFromDt

    that "Call" raises a missing parameter error.

    That is the wrong use for a Function because you are not using its returned Value. But you are modifying a worksheet with it.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by SamT; 06-09-2015 at 12:03 AM.

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,963

    Re: [Urgent] Problems about looping in the following program

    1. A basic function is meant to return a single value to a single cell in the worksheet (the cell containing the function).
    2. The function must have a line that assigns the calculated value to the cell containing the function. In the function CubeRt()

    Please Login or Register  to view this content.
    3. In your function, you have the line: MonthFromDt = Month(DateSerial(yr, 1, 1) + 7 * (wk - 1)) which should return the calculated month to the cell.

    The function should have ended with that line; instead, it is followed by the line:
    Range("AO" & CStr(k)) = MonthFromDt

    You are trying to write the month to a series of cells (2060 cells!) in the worksheet using a loop.
    What it is actually doing is trying to call the function from within the function itself (it's called recursion).
    The function requires a string to be passed to the variable "s" but you are passing nothing so the program crashes.

    The function should look like:
    Please Login or Register  to view this content.
    I don't know why you need the vb function, it can be done directly in the cell using:
    Please Login or Register  to view this content.
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] A looping program that selects a column and appends a set string of data
    By JamesJohnson31 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-30-2014, 03:12 PM
  2. [SOLVED] Help on looping program logic
    By trizzo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-15-2013, 12:36 PM
  3. LOOPING appx 500 ++ million times, how to fasten this program?
    By JohnSeito in forum Excel Programming / VBA / Macros
    Replies: 37
    Last Post: 06-27-2008, 11:06 PM
  4. [SOLVED] Help with simple looping program
    By Stephen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-04-2006, 02:00 PM
  5. Looping Program
    By bs272 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-26-2006, 12:55 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1