The only information that needs input is the PO number and the date with the corresponding Req Number that was selected from the list
VBA - Sorting Formula has stopped working
- Jeffrey Smith
- Thread is marked as Resolved.
-
-
It should not be there. The code is putting the value into the 13th column of the new row.
-
Yes I took the 1 off of Value and it is placing the information on the wrong line and also information that is already on that line. The purpose of this UserForm is to search/Filter through the "Parts List" sheet by Req Number and place the associated PO Number and date entered with all lines that include the that Req Number
-
Your code adds a new row to the table and populates that. There is no "information already on that line" since it's a new line (other than any table formulas that fill down).
-
Your code adds a new row to the table and populates that. There is no "information already on that line" since it's a new line (other than any table formulas that fill down).
Thats my point. First off its not my code that is what someone at the beginning of this post placed in there and I am new at this. they changed my code and said I was doing it work for a Table. So I asked how I should be doing this and that was the code they inserted. I don't need a new line I need the information to be placed along with all the lines that has the same associated Req number that was selected from the drop down list.
This is the Original Code that was causing me issues in the first place.
Code
Display MorePrivate Sub OkBtn_Click() 'Check For Required Fields Dim Last As Long Last = Sheet7.Cells(Rows.Count, 12).End(xlUp).row If ReqLst.Value = Empty Or PO.Value = Empty Or DateEntered.Value = Empty Then MsgBox "Please Make Sure to Fill in All Fields Before Saving" Exit Sub End If Sheets("Parts List").Unprotect Password:="Engineering" With Sheet7 .ListObjects("PartsTbl").Range.AutoFilter Field:=12, Criteria1:=ReqLst.Value .Range("M3:M" & Last).SpecialCells(xlCellTypeVisible).Value = PO.Value .Range("N3:N" & Last).SpecialCells(xlCellTypeVisible).Value = DateEntered.Value .ListObjects("PartsTbl").Range.AutoFilter Field:=12 End With Sheets("Parts List").Protect Password:="Engineering", _ AllowSorting:=True, _ AllowFiltering:=True Me.ReqLst.Value = "" Me.PO.Value = "" End Sub
-
-
The original code works as long as there is more than one item in on the "parts list" sheet. If I have multiple Req's in there it works perfect but if there is only one in there just like the first example I attached in first post, then it freaks out and places the PO number into literally every cell in the sheet and overloads the workbook till it runs out of memory.
-
If you use Specialcells on a single cell range (which is what happens when you have one row of data), it is applied to the entire worksheet. You need to test if Last = 3, and if it is, test if row 3 is hidden, instead of using SpecialCells.
-
If you use Specialcells on a single cell range (which is what happens when you have one row of data), it is applied to the entire worksheet. You need to test if Last = 3, and if it is, test if row 3 is hidden, instead of using SpecialCells.
How can I test this...I'm sorry I am New to VBA Code?
-
Something like this:
Code
Display MorePrivate Sub OkBtn_Click() 'Check For Required Fields Dim Last As Long Last = sheet7.Cells(Rows.Count, 12).End(xlUp).Row If ReqLst.Value = Empty Or PO.Value = Empty Or DateEntered.Value = Empty Then MsgBox "Please Make Sure to Fill in All Fields Before Saving" Exit Sub End If sheet7.Unprotect Password:="Engineering" With sheet7 .ListObjects("PartsTbl").Range.AutoFilter Field:=12, Criteria1:=ReqLst.Value If Last > 3 Then .Range("M3:M" & Last).SpecialCells(xlCellTypeVisible).Value = PO.Value .Range("N3:N" & Last).SpecialCells(xlCellTypeVisible).Value = DateEntered.Value Else If .Rows(3).EntireRow.Hidden = False Then .Range("M3").Value = PO.Value .Range("N3").Value = DateEntered.Value End If End If .ListObjects("PartsTbl").Range.AutoFilter Field:=12 End With sheet7.Protect Password:="Engineering", _ AllowSorting:=True, _ AllowFiltering:=True Me.ReqLst.Value = "" Me.PO.Value = "" End Sub
-
Jeffrey Smith
Selected a post as the best answer. -
That worked perfectly!
thank you so much!
I was trying to write it out myself and I was on the right track, but I was still doing it wrong. So thank you for taking the time to write it out for me. Once I see it then it all makes sense.
I am a PLC Ladder logic programmer and have no experience with Structured text so VBA is New to me and I thank you for all your help
-
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!