• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Loop code and Increment specific range to set value

Bilofkd

New Member
Greetings!

I am to chandoo so forgive me if I missed any instruction.

I have a simple userform that adds data to a table, like Date, Name, Units, etc

I need the data to be inserted on the table n amount of times, n is in defined by a cell in "calcs!A3"

For each new line inserted the date would increment by the value on a given cell, for example 15. And Units would increment by value of another cell

Right now all I have is userform looping code but no increment

Code:
Private Sub cmdAdd_Click()
Dim iRow As Long

Dim ws As Worksheet
Set ws = Worksheets("calcs")

Dim i As Long

For i = 1 To Range("calcs!A3")


iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1


ws.Cells(iRow, 2).Value = Format(txtData, "mm/dd/yyyy")
ws.Cells(iRow, 1).Value = Me.TextBox2.Value
ws.Cells(iRow, 3).Value = Me.ComboBox1.Value
ws.Cells(iRow, 5).Value = Me.ComboBox3.Value
ws.Cells(iRow, 4).Value = Me.ComboBox2.Value
ws.Cells(iRow, 6).Value = Me.TextBox5.Value
ws.Cells(iRow, 7).Value = Me.TextBox3.Value
ws.Cells(iRow, 8).Value = Me.TextBox4.Value

Next i


Me.TextBox2.Value = "CR-"
Me.ComboBox1.Value = ""
Me.ComboBox3.Value = ""
Me.ComboBox2.Value = ""
Me.TextBox5.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""


End Sub

I appreciate any help!

Regards
 
A guess, try changing:
ws.Cells(iRow, 2).Value = Format(txtData, "mm/dd/yyyy")
to:
ws.Cells(iRow, 2).Value = Format(txtData+i-1, "mm/dd/yyyy")
 
Back
Top