Growing tired of crazy Excel calisthenics to display certain data, I decided to develop a For Loop UDF. It works ok, if yet a little clunky. Here's the code:
Use:
Like I said, it works ok. My biggest beef is that there are so many arguments, and it's difficult (yet possible and quick) to increment horizontally (with OFFSET()).
My question:
What do you guys think, can I ditch some of these arguments?
and also:
Can I make this more robust without losing efficiency?
Code:
Function FORLOOP(
ByVal string_variable As String,
ByVal start_value As Long,
ByVal value_limit As Long,
ByVal value_increment As Long,
ByVal string_formula As String,
ByVal string_separator As String,
ByVal application_volatile As Boolean)
Dim i As Long
If application_volatile Then Application.Volatile
For i = start_value To value_limit - 1 Step value_increment
FORLOOP = FORLOOP & Evaluate(Replace(string_formula, "#" & string_variable, i)) & string_separator
Next i
FORLOOP = FORLOOP & Evaluate(Replace(string_formula, "#" & string_variable, i))
End Function
Use:
Code:
=FORLOOP("a",3,12,1,"OFFSET(B1,0,#a)","|",FALSE)
[i]Displays E1 through M1, pipe delimited[/i]
Like I said, it works ok. My biggest beef is that there are so many arguments, and it's difficult (yet possible and quick) to increment horizontally (with OFFSET()).
My question:
What do you guys think, can I ditch some of these arguments?
and also:
Can I make this more robust without losing efficiency?