Update:
Every time the tab is opened it automatically generates the an order list.
As far as I can tell, there is one bug in the code:
- The first line on "Full List" (in this case C8:P8) is always copied and inserted into the new array no matter what is there.
I made it copy a blank row, but the paste into the Order tab should only list order items. I tried pasting all items from the results array aside from the first row but to no success. Oh and thank you so much @David-Zemens for all the assistance on this. You know what you are doing and it shows :)
Private Sub Worksheet_Activate()
Dim wsList As Worksheet, wsOrder As Worksheet
Dim rng As Range
Set wsList = Worksheets("Full List")
Set wsOrder = Worksheets("Order")
wsList.Unprotect
'Clear Columns B, C, & D below row 3 in the Order sheet
wsOrder.Range("B3:D" & Rows.Count).ClearContents
'Set Range to include all columns from C to P starting with row 8
Set rng = wsList.Range("C8:P" & GetLastRow(wsList, 3))
wsList.AutoFilterMode = False
'filter so that only numeric values in column P are showing
rng.AutoFilter Field:=14, Criteria1:=">0", _
Operator:=xlAnd
'Copy column C (in wsList) to column B (in wsOrder)
rng.Columns(1).SpecialCells(xlCellTypeVisible).Copy
wsOrder.Range("B2").PasteSpecial xlPasteValues
'Copy column D (in wsList) to column C (in wsOrder)
rng.Columns(2).SpecialCells(xlCellTypeVisible).Copy
wsOrder.Range("C2").PasteSpecial xlPasteValues
'Copy column P (in wsList) to column D (in wsOrder)
rng.Columns(14).SpecialCells(xlCellTypeVisible).Copy
wsOrder.Range("D2").PasteSpecial xlPasteValues
wsList.AutoFilterMode = False
wsList.Protect
End Sub
Function GetLastRow(sh As Worksheet, column As Long)
' Function will return the last effective cell in specified column on worksheet
' sh: Worskheet object i.e., Worksheets("Sheet1")
' column: long/integer value of column, i.e., column A = 1, column N = 12, etc.
' Modified from :
' http://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-vba
'
With sh
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
lastRow = .Cells.Find(What:="*", _
After:=.Cells(1, column), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
lastRow = 1
End If
End With
GetLastRow = lastRow
End Function
Original Post:
I was hoping that someone might be able to assist.
I created an excel program that allows me to see what the stock levels are and to compare it against counted or expected values. This allows me to see how many items we need to order.
What I was hoping to do was generate (on another tab) a separate list that only shows me the Product Code, Product Name, and the Quantity to order.
The main tab where everything is counted is named "Full List" aka Sheet06.
There are multiple rows, but the ones that I am interested in start at row 9 and are on columns C (Product Code), D (Product Name), & P (How many to Order) and there are over a thousand rows of product with some blank rows used to try to make it easy to read (if needed these lines can be filled with something or use column Q to have a TRUE/FALSE "=ISNUMBER(P9)" equation)
On Column P, if an order is not needed there is a blank space (="") or text
|A|B|Product Code|Name |E|F|G|H|I|J|K|L|M|N|O|Order
9 | | |00002 |something| | | | | | | | | | | |""
10| | |345663 |something| | | | | | | | | | | |3
11| | |6534214 |something| | | | | | | | | | | |15
12| | | | | | | |(Blank row)| | |
13| | |24435224 |something| | | | | | | | | | | |DONT ORDER
14| | |8784347 |something| | | | | | | | | | | |8
15| | |357823 |something| | | | | | | | | | | |""
What I have been trying to create (and failing) is another tab called "Order" aka Sheet07
It is supposed to copy over the Product Code, Name, and how many to order if and only if there is a number on row P on the other tab. Also this would have to copy over the value generated for the order (18, 4, etc) not the formula (=E9-F9+G9....).
|A|Product Code|Name |Order
4| |345663 |something|3
5| |6534214 |something|15
6| |8784347 |something|8
I have been struggling with this for quite a while now and I have reached a mental roadblock.
Any help would be appreciated :)