JamesW
Well-known Member
- Joined
- Oct 30, 2009
- Messages
- 1,197
Hey guys,
Thought I'd post a little something I've been working on. I'd like to know what things people would do differently if they could change anything.
Don't laugh when you see it, I'm still very delicate from last night with Jon Von and Mike...
Always up for constructive criticism, and I am always looking to learn new things.
Cheers,
James
Thought I'd post a little something I've been working on. I'd like to know what things people would do differently if they could change anything.
Don't laugh when you see it, I'm still very delicate from last night with Jon Von and Mike...
Always up for constructive criticism, and I am always looking to learn new things.
Code:
Option Explicit
Dim lRow, NPILRow, i, j, n As Integer
Dim FileToOpen As String
Dim MyBook, ThisWB As Workbook
Dim cell As Variant
Dim fileNCheck As VbMsgBoxResult
Sub Main()
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
Set ThisWB = ThisWorkbook
NPILRow = Range("C" & Rows.Count).End(xlUp).Row
Range("S8:S" & NPILRow).Copy Destination:=Range("R8:R" & NPILRow)
FileToOpen = Application.GetOpenFilename _
(Title:="Please choose the latest xxx file", _
FileFilter:="Excel Files *.xls (*.xls),")
If FileToOpen = "False" Then
MsgBox "No file specified."
Exit Sub
Else
If Not FileToOpen Like "*xxx*" Then
fileNCheck = MsgBox(FileToOpen & " is not a recognised file/filename. Please ensure that you are using an APO file. " & vbNewLine & vbNewLine & "Do you wish to continue regardless? Doing so may produce incorrect results", vbYesNo)
If fileNCheck = vbNo Then
Exit Sub
End If
End If
Set MyBook = Workbooks.Open(Filename:=FileToOpen)
End If
With MyBook.Sheets("Sheet1")
lRow = .Range("AL" & Rows.Count).End(xlUp).Row
For i = 2 To lRow
For j = 38 To 193
If .Cells(i, j).Value <> 0 Then
If j = 38 Then
.Range("AK" & i).Value = "From Now"
Exit For
Else
.Range("AK" & i).Value = Cells(1, j).Value
Exit For
End If
Else
.Range("AK" & i).Value = "No FC"
End If
Next j
Next i
End With
With ThisWB.Sheets("SKU Completed")
.Range("S8").Value = "=VLOOKUP(RC[-16],'" & FileToOpen & "'!C1:C37,37,FALSE)"
.Range("S8").AutoFill (.Range("S8:S" & NPILRow))
.Range("T8").Value = "=IF(OR(RC[-1]=""No FC"",RC[-1]=""From Now""),""Unknown"",IF(and(MID(RC[-1],FIND(""."",RC[-1],1)+1,(FIND(""."",RC[-1],3)-FIND(""."",RC[-1],1)-1))+0-RC[-4]<=1,MID(RC[-1],FIND(""."",RC[-1],1)+1,(FIND(""."",RC[-1],3)-FIND(""."",RC[-1],1)-1))+0-RC[-4]>=-1),""OK"",""Issue""))"
.Range("T8").AutoFill (.Range("T8:T" & NPILRow))
End With
ThisWB.Activate
MyBook.Close SaveChanges:=True
Range("S8:T" & NPILRow).Copy
Range("S8:T" & NPILRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub
James
Last edited: