Function Help

  • Thread starter Thread starter Michael168
  • Start date Start date
M

Michael168

Hi !

I need some help to finish my little function as below. Even though th
task can be accomplish using the formula but I just want to learn how t
code.

Private Function GetConsecutive(ByVal row&)
Dim i As Integer
Dim v As Integer
Dim Consecutive As Integer
For i = 1 To 4
v = Cells(row, FirstNumberColumn + i - 1)

*** How to add the extra code from below to count the Consecutive?
In plain english;
if 2nd v - 1st = 1 then consecutive = consecutive + 1
if 3rd v - 2nd = 1 then consecutive = consecutive + 1
if 4th v - 3rd = 1 then consecutive = consecutive + 1
else
consecutive=0
endif

Next

Getconsecutive = consecutive
End Function

Thank you for helping.

Regards,
Michae
 
make these changes

dim (v(4) as integer
For i = 1 To 4
v(i) = Cells(row, FirstNumberColumn + i - 1)
next i



add
for i = 2 to 4
if v(i) - v(i-1) = 1 then concsecutive = consecutive + 1
next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top