View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
excelnut1954 excelnut1954 is offline
external usenet poster
 
Posts: 175
Default Need a macro to loop evaluation of many textboxes in a UserForm.

Getting closer. This is all making much more sense as I break it apart.


I got everything as you originally posted above except that I added the
last line you gave me. . The complete code is below. I tested it again,
and I entered 3 records, that is, TextBoxes 1, 3 & 5 for the PO#, boxes
2, 4 & 6 for the Taken By, and boxes 27, 28 & 29 for the Pieces.
(TextBox41 - Default date - goes with every record to be posted)
I ran it, and the result was that the 1st 2 records were posted fine,
but only the Date posted for the 3rd record. It didn't read TextBoxes6
& 29. It must have read TextBox5 ok, since it posted the date on that
line.

Well, here's the code up to now. I'll try it later on, filling up all
13 records to be posted. I suspect that after the 2nd record, only the
Date will be posted for the other 11 records.
Thanks again for the help, AND your time.
J.O.

Sub DeleteTest()
Dim i As Long

For i = 1 To 13
'This will check to make sure there is 1
'and only 1 of this PO number on list.
If Me.Controls("TextBox" & i * 2 - 1).Text < "" Then
PONum = Me.Controls("TextBox" & i * 2 - 1).Text

' Worksheets("Official List").Activate
CountPOtoValidate = Application.CountIf(Range("J:J"),
PONum)
End If

If CountPOtoValidate < 1 Then
MsgBox "This record does not exist on the list." &
vbNewLine & _
"Please check the PO number and try again"

ElseIf CountPOtoValidate 1 Then
MsgBox "There are duplicate records." & vbNewLine & _
"Highlight this record on the list, then see the
supervisor."

Else

'This will post the entries from TextBoxes 2, 27 & 41
'for the PO# entered in TextBox1, 3, 5, etc.
Set rngToSearch = Sheets("Official List").Columns("J")
Set rngFound = rngToSearch.Find(What:=PONum, _
LookIn:=xlValues)

rngFound.Select
ActiveWorkbook.Names.Add Name:="DeletePOCell",
RefersTo:=ActiveCell

Application.Goto Reference:="DeletePOCell"
ActiveCell.Offset(0, 4).Select
Application.Selection.Value = _
Me.Controls("TextBox" & 26 + i).Text 'Pieces moved
ActiveCell.Offset(0, 2).Select
Application.Selection.Value = _
UCase(Me.Controls("TextBox" & i * 2).Text) 'Taken By
ActiveCell.Offset(0, 1).Select
Application.Selection.Value = TextBox41.Text 'Default
date
Cancel = False
ActiveWorkbook.Names("DeletePOCell").Delete

End If

Next i

End Sub