Hi,
I'm new to VBA so I get stuck from time to time
Since a couple of days I was struggeling with the For Each Loop in combination with getting the value from textboxes in a userform and copying these to excel...
The code picks up de data entered in the userform textbox's but instead of adding them only one time for each textbox value it's adding it 91 time, that 1820 lines added to excel and I just need the text of all 20 textboxes once
Does anybody know what the problem is with my code?
Thanks for the help!
I'm new to VBA so I get stuck from time to time
Since a couple of days I was struggeling with the For Each Loop in combination with getting the value from textboxes in a userform and copying these to excel...
The code picks up de data entered in the userform textbox's but instead of adding them only one time for each textbox value it's adding it 91 time, that 1820 lines added to excel and I just need the text of all 20 textboxes once
Does anybody know what the problem is with my code?
Code:
Dim i As Integer
Dim TextData As String
Dim lastRow As Long
For i = 1 To 20
For Each txtPart In Controls
TextData = Controls("txtPart" & i).Value
lastRow = Sheets("DePop").Range("A" & Rows.Count).End(xlUp).Row
Sheets("DePop").Cells(lrReg + 1, "A").Value = TextData
Next txtPart
Next i