Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 49948

Vlookup data and compare variances

$
0
0
Hi

I have begun the macro coding for a stock report. The macro report has on sheet 3 the minimum stock numbers for each item which has a 5 digit stock code which I was hoping to vlookup in a weekly report to give the variances - which will in turn give an indication of which items need restocked/replenished etc and displayed on sheet 2.

Here is my code so far - can someone please please help me with how to use the v lookup on a loop ? or is there an easier way.

Code:


Sub Paul()


Application.DisplayAlerts = False
MFile = ActiveWorkbook.Name
Application.ScreenUpdating = False

WeeklyFN = Application.GetOpenFilename(fileFilter:="All files (*.*), *.*", Title:="Paul- Please open weekly stock report")
If WeeklyFN = "False" Or WeeklyFN = "" Then
    MsgBox "You have not selected a file."
    Exit Sub
Else
  Workbooks.Open Filename:=WeeklyFN
    WeeklyFN = ActiveWorkbook.Name
    MsgBox "You selected " & WeeklyFN, Title:="Paul  - GTRS File Selected"
End If

Cells.Select
    ActiveWorkbook.Worksheets("Table1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Table1").Sort.SortFields.Add Key:=Range("B2:B5000") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Table1").Sort
        .SetRange Range("A1:E612")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A1").Select
   
   
    Windows("PAULS STOCK WORKSHEET.xlsm").Activate
    Sheet2.Activate
    With Sheets(2)
    .UsedRange.ClearContents
    .Columns(1).NumberFormat = "@"
    .[a1:e1].Value = Array("stock_code", "stock_name", "minimum holding", "current stock", "variance")
    End With
    Range("A2").Select
   

End Sub
PAULS STOCK WORKSHEET.xlsmXL_Export.xlsb


The export file will be a weekly report that will be used to compare against the permanent file held on sheet 3 in "PAULS STOCK WORKSHEET.xlsm" I only want those stock items which are negative reported in sheet 2

Attachment 303931Attachment 303932

Many thanks in advance

Viewing all articles
Browse latest Browse all 49948

Trending Articles