Search code examples
excelvbauserform

How to set up my input data on a specific cell in Userform?


I want to start adding data from a specific cell and stop at another cell. From I7:I10 to T7:T10. But I want to enter the data from the Userform. But whenever I entered the data, it is saying I am on Cell 16,000 something.

I have two data set, and one tab in the userform work well, it would enter the data in rows. But for the other tab, I would like it to enter it by the next column. I have data below I7 by the way. But some of the areas are blank and some with data. One of the tabs from Userform is going to a separate sheet called Employee and the other going to TestCal.

Private Sub CBSave_Click()

Dim lrEmp as Long
Dim lrCal as Long

'This part work fine
lrEmp = Sheets("Employee").Range("A" & Rows.Count).End(xlUp).Row
With Sheets("Employee")
    .Cells(lrEmp + 1, "A").Value = tbEmpID.Text
    .Cells(lrEmp + 1, "B").Value = tbName.Text
    .Cells(lrEmp + 1, "C").Value = tbLast.Text
End With

'This is the part I am having trouble with
lcCal = Sheets("TestCal").Range("Sales") .End(xlToLeft).Column
With Sheets("TestCal")
     .Cells(lrCal, "I").Value = tbApple.Text
     .Cells(lrCal + 1, "I").Value = tbOrange.Text
     .Cells(lrCal + 2, "I").Value = tbBanana.Text
End With

End Sub

I think I set up my column one wrong, how would I set it up where the next data entry will go to the right. Right now, the data entry is being inputted all the way down to the 16,000 cells for some reason.

**Forgot to mention this, tbApple, tbOrange, and tbBanana are all in the same column. I want to get the next column with them like that.

I hope I am making sense. Thank you.


Solution

  • Not sure where 7 through 10 comes from, maybe 7 is a header?

    'This is the part I am having trouble with
    lcCal = Sheets("TestCal").Cells(7,columns.count).End(xlToLeft).Column + 1
    With Sheets("TestCal")
         .Cells(8, lcCal).Value = tbApple.Text
         .Cells(9, lcCal).Value = tbOrange.Text
         .Cells(10, lcCal).Value = tbBanana.Text
    End With
    
    End Sub