Function in a loop (1 Viewer)

bastanu

AWF VIP
Local time
Today, 04:53
Joined
Apr 13, 2010
Messages
1,402
That is what I had in post 10 as the first alternative, but that is not the problem.
A VBA function returns a value; in your you do not as you are using a variable declared in an external sub to assign the value to. You need to replace "startRange" with "BeginDate" everywhere within the function code (and a similar change for the other).
 

bastanu

AWF VIP
Local time
Today, 04:53
Joined
Apr 13, 2010
Messages
1,402
Code:
Private Function BeginDate(rsLeave As Date, rownum) As String

    
If Month(rsLeave) = "1" Then
    If Day(rsLeave) = "1" Then
        BeginDate = "CR" & rownum
 

Valentine

Member
Local time
Today, 07:53
Joined
Oct 1, 2021
Messages
261
YES!!!!! awesome thank you soo much it works just like I want it to.
 

bastanu

AWF VIP
Local time
Today, 04:53
Joined
Apr 13, 2010
Messages
1,402
(y) :)
You're very welcome, good luck with your project!
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:53
Joined
Sep 21, 2011
Messages
14,350
Instead of writing a humingous piece of code hardcoded, you can refer to a range by column and row numbers. So should be easy to calculate in a few lines?

 

Valentine

Member
Local time
Today, 07:53
Joined
Oct 1, 2021
Messages
261
Yeah but the functions were giving me the specific cell based on 3 different unknowns. The spreadsheet was a home made colander of sorts, row 1 had the months by name "January", "February", and so on as merged cells since row 2 had the number day of the month "1", "2", and so on. So I had to go through the record set of dates and pull out the month of each day to get the 1st range and then the day of the date to get the actual column title "A", "B", and so on. I had the rownum variable already pull the row value so I just combined the function with the rownum variable to give the specific cell each date refered to. I was pulling the dates in from a recordset from access.
 

Users who are viewing this thread

Top Bottom