I am trying to use the following code I found on the web but it stops due to a syntax error:see below
Sub TestCNR()
Cnr 10, 4
End Sub
Sub Cnr(n, r)
i = 1
For j = 1 To r
Cells(i, j).Value = j
Next
Do Until Finished(n, r, i)
j = FindFirstSmall(n, r, i)
' The error occures in below line
For k = 1 To j – 1
Cells(i + 1, k).Value = Cells(i, k).Value
Next
Cells(i + 1, j).Value = Cells(i, j).Value + 1
For k = j + 1 To r
Cells(i + 1, k).Value = Cells(i + 1, k - 1).Value + 1
Next
i = i + 1
Loop
End Sub
Function Finished(n, r, i)
Temp = True
For j = r To 1 Step -1
If Cells(i, j).Value <> j + (n - r) Then
Temp = False
End If
Next
Finished = Temp
End Function
Function FindFirstSmall(n, r, i)
j = r
Do Until Cells(i, j).Value <> j + (n - r)
j = j - 1
Loop
FindFirstSmall = j
End Function
Can someone advise cause of error please?
For k = 1 To j - 1
**
as the OP showing us where the syntax error is... which I can replicate by pasting OP's code (without the**
's) in the VBE.** **
marks replaced with a comment.