Take a look at the example below. It is from development version of ALGLIB which is somewhere between 2.6 and 3.0, but it should be compatible with ALGLIB 2.6 (you may nned to change one or two function names, and that's all). The main idea is that you initialize fitting object, and then repeatedly call LSFitNonlinearIteration(), updating function value and/or gradient (depending on what is requested by algorithm).
Unfortunately, this example is not distributed with ALGLIB for VBA, because all my example are console-oriented, and VBA does not supports console, so you can't compile it (it contains calls to ConsoleOutputString() function, which is not provided by VBA).
Code:
Public Sub DemoRoutine()
Dim M As Long
Dim N As Long
Dim K As Long
Dim Y() As Double
Dim X() As Double
Dim C() As Double
Dim Rep As LSFitReport
Dim State As LSFitState
Dim Info As Long
Dim EpsF As Double
Dim EpsX As Double
Dim MaxIts As Long
Dim I As Long
Dim J As Long
Dim A As Double
Dim B As Double
ConsoleOutputString "Fitting 0.5(1+cos(x)) on [-pi,+pi] with exp(-alpha*x^2)" _
& vbNewLine
'
' Fitting 0.5(1+cos(x)) on [-pi,+pi] with Gaussian exp(-alpha*x^2):
' * without Hessian (gradient only)
' * using alpha=1 as initial value
' * using 1000 uniformly distributed points to fit to
'
' Notes:
' * N - number of points
' * M - dimension of space where points reside
' * K - number of parameters being fitted
'
N = 1000#
M = 1#
K = 1#
A = -Pi()
B = +Pi()
'
' Prepare task matrix
'
ReDim Y(0 To N-1)
ReDim X(0 To N-1, 0 To M-1)
ReDim C(0 To K-1)
For I=0# To N-1# Step 1
X(I,0#) = A+(B-A)*I/(N-1#)
Y(I) = 0.5*(1#+Cos(X(I,0#)))
Next I
C(0#) = 1.0
EpsF = 0.0
EpsX = 0.0001
MaxIts = 0#
'
' Solve
'
Call LSFitNonlinearFG(X, Y, C, N, M, K, True, State)
Call LSFitNonlinearSetCond(State, EpsF, EpsX, MaxIts)
Do While LSFitNonlinearIteration(State)
If State.NeedF then
'
' F(x) = Exp(-alpha*x^2)
'
State.F = Exp(-(State.C(0#)*Square(State.X(0#))))
End If
If State.NeedFG then
'
' F(x) = Exp(-alpha*x^2)
' dF/dAlpha = (-x^2)*Exp(-alpha*x^2)
'
State.F = Exp(-(State.C(0#)*Square(State.X(0#))))
State.G(0#) = -(Square(State.X(0#))*State.F)
End If
Loop
Call LSFitNonlinearResults(State, Info, C, Rep)
ConsoleOutputString "alpha: " & FormatFReal(C(0#), 0, 3) _
& vbNewLine
ConsoleOutputString "rms.err: " & FormatFReal(Rep.RMSError, 0, 3) _
& vbNewLine
ConsoleOutputString "max.err: " & FormatFReal(Rep.MaxError, 0, 3) _
& vbNewLine
ConsoleOutputString "Termination type: " & FormatInteger(Info, 0) _
& vbNewLine
ConsoleOutputString vbNewLine & vbNewLine
End Sub