Hi everyone, I"m still new in VBA and currently working on to develop data entry form in excel. I'm facing errors where my ID cannot auto increment while inserting the data=Country with 10 rows once the button was clicked. My codes are getting errors by overwritten the previous data for next clicked button. ERRORS in LOOPING and ID AUTO INCREMENT !!
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Country[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]16[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]17[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]18[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]19[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]20[/TD]
[TD]USA[/TD]
[/TR]
</tbody>[/TABLE]
Code:
Sub test()
Sheet1.Activate
Range("A1").End(xlDown).Offset(1,0).Select
ActiveCell.Value = ActiveCell.Value + 1
ActiveCell.Offset(0, 1).Value = cboCountry.Value
Dim loopCounter As Integer
For loopCounter = 1 To 10
ActiveCell.Value = ActiveCell.Value = loopCounter + 1
ActiveCell.Offset(loopCounter, 1).Value = cboCountry.Value
Next loopCounter
End sub
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Country[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]UK[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]16[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]17[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]18[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]19[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD]20[/TD]
[TD]USA[/TD]
[/TR]
</tbody>[/TABLE]