Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
In a User Form, the user enters in records to be removed from the list.
He will enter info in the textboxes in the following layout. It will allow 13 records to be identified in the userform. Textboxes 1-25 (odd numbers only) are for "PO Numbers" (13 total records). Textboxes 2-26 (even numbers only) are for "Taken By". TextBoxes 27-39 are for "Pieces Moved". Textbox 41 is the default date to be applied to each record. Together, this allows for 13 records to be designated for delete. This puts data in for each of the records. A macro later will actually remove them from the list. The For-Next below will look at each of the "PO Number" boxes, and if there is an entry, will test to make sure it's on the list, and also for duplicates. Then it will post the "Taken By", "Pieces Moved", and the default date to that record on the list. The good news is if all of the textboxes (13 records) are filled, then this works perfect. Here's the problem: If there are any less than 13 PO Numbers entered, then only the 1st record is done correctly. Only the default date is entered for the others. The "Pieces Taken", and "Taken By" data is not. Can anyone figure out why this will work only if all 13 records are filled in? I'm just learning about the For-Next loops, so it's hard for me to see what may be the problem. Thanks to Bob Phillips for the core of this sub. Maybe Bob, or someone else can stumble upon this, and figure out what I'm looking for. Thanks, J.O. Declarations Public rngToSearch As Range Public rngFound As Range Public PONum As String Public CountPOtoValidate As String 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. Worksheets("Official List").Activate 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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Colon at the end of excel file name(ex: problem.xls:1, problem.xls | New Users to Excel | |||
Started out as an Access problem. Now an Excel problem | Excel Discussion (Misc queries) | |||
problem with a conditional max problem | Excel Discussion (Misc queries) | |||
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? | Excel Programming |