Link to home
Start Free TrialLog in
Avatar of cmoore1
cmoore1

asked on

excel macro

I'm looking for a macro to fill a column with incrementing numbers. starting it with the value of the current cell then moving down the spread sheet incrementing the the by 1 with each move until i reach a predetermined number.
Avatar of StephenJR
StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

This will stop at 50:
ActiveCell.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Step:=1, Stop:=50

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Glenn Ray
Glenn Ray
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cmoore1
cmoore1

ASKER

I must need more than this, I get a compiler erro "expected:named parameter" with tpye highlighted
That error would occur if the command in line 5 of my code was split up to two lines like so:
 
ActiveCell.DataSeries Rowcol:=xlColumns,
   Type:=xlLinear, Step:=1, Stop:=intFinal

Open in new window


If you need to format your code like that, add an underscore at the end of the first line so that the compiler will continue reading to the next line, as here:

 
ActiveCell.DataSeries Rowcol:=xlColumns, _
   Type:=xlLinear, Step:=1, Stop:=intFinal

Open in new window


If this still doesn't resolve your issue, let us know.

-Glenn
Here is alternate code if that doesn't work.
 
Sub Increment()
    Dim x, intFinal As Integer
    intFinal = Application.InputBox("Enter Final Value:", , , , , , , 1)
    If intFinal > ActiveCell.Value Then
        For x = ActiveCell.Value + 1 To intFinal
            ActiveCell.Offset(x - ActiveCell.Value, 0).Value = x
        Next x
    End If
End Sub

Open in new window


Avatar of cmoore1

ASKER

Glen
running this galso gives me an error user-defined type not defined.
Highlighting " intFinal As Integer"
Avatar of cmoore1

ASKER

Glen
running this alternate code also gives me an error user-defined type not defined.
Highlighting " intFinal As Integer"
You probably need to Repair or re-install Excel then.  These definitions are part of the Excel object library reference and shouldn't give you any errors whatsoever.  I can't think of any other reason why this wouldn't work.

-Glenn
Avatar of cmoore1

ASKER

Thanks,
I will try it. I'm out of town currently. I'll try this when I get back.
Thanks again.
Charlie