Private Sub CommandButton1_Click()
Dim wbReview As Workbook, wbExport As Workbook, wsReview As Worksheet, wsExport As Worksheet
Dim sReview As String, sExport As String, Rpath As String, Epath As String, FEpath As String, efil_nam As String
Dim Border_rng As Range, frmt_rng As Range, iss_num As Variant
Dim data_val() As Double, sn_val() As String, oper_val() As String, dt_val() As String, tm_val() As String
Dim MyList As String
With Application
.ScreenUpdating = False
.DisplayAlerts = False
iWindowState = .WindowState
.WindowState = xlMinimized
End With
f_day = Day(Now)
f_mnth = Month(Now)
f_hr = Hour(Now)
f_min = Minute(Now)
f_ap = "A"
If f_hr < 10 Then
f_hr = Str("0" + f_hr)
End If
If f_min < 10 Then
f_min = Str("0" + f_min)
End If
If f_hr > 12 Then
f_hr = f_hr - 12
f_ap = "P"
End If
f_set = f_mnth & "_" & f_day & "_" & f_hr & f_min & f_ap
temp_dest = "C:\Eric\"
Set wbReview = ActiveWorkbook
Set wsReview = wbReview.Worksheets("Master_Data")
fl_split = wsReview.Range("D2").Value
iss_num = Format(wsReview.Range("E2").Value, "Standard")
pn_v = Split(fl_split, "_")(0) 'part number
pt_v = Split(fl_split, "_")(1) 'prog type
po_v = Split(fl_split, "_")(2) 'OP number
pm_v = Split(fl_split, "_")(3) 'Mach ID
efil_nam = fl_split & "-" & iss_num 'file and sheet title
Epath = "M:\Reports Archive\" & pn_v & "\" & "OP" & po_v & "\Export" 'Export folder location (2020 Template)
sExport = efil_nam & ".csv" 'CSV file name
FEpath = Epath & "\" & sExport
f_title = temp_dest & fl_split & "_" & f_set
Set wbExport = Workbooks.Open(FEpath)
Set wsExport = wbExport.Worksheets(efil_nam)
lastr = 0
lastc = 0
ir = 10
ic = 19
csvdata_start = 3
wsExport.Activate
wsExport.Range("A1").Activate
While Not ActiveCell = ""
lastr = lastr + 1
ActiveCell.Offset(1, 0).Activate
Wend
wsExport.Range("A1").Activate
While Not ActiveCell = ""
lastc = lastc + 1
ActiveCell.Offset(0, 1).Activate
Wend
ReDim sn_val(1 To lastr) As String
ReDim oper_val(1 To lastr) As String
ReDim dt_val(1 To lastr) As String
ReDim tm_val(1 To lastr) As String
ReDim data_val(1 To lastc) As Double 'was long when working
v = 0
While x < lastr
x = x + 1 'begins rows
wsExport.Activate
sn_val(x) = wsExport.Cells(x, 1).Value
oper_val(x) = wsExport.Cells(x, 2).Value
dt_val(x) = wsExport.Cells(x, 3).Value
'tm_val(x) = wsExport.Cells(x, 4).Value
While y < (lastc - csvdata_start) 'begin column
y = y + 1
data_val(y) = wsExport.Cells(x, y + csvdata_start).Value
data_val(y) = Format(data_val(y), "0.0000")
Wend 'end column
y = 0
wsReview.Activate
wsReview.Cells(ir + 1, ic + x).Resize(UBound(data_val), 1).Value = Application.Transpose(data_val)
Wend
y = 0
x = 0
While x < lastr
x = x + 1
wsReview.Activate
wsReview.Cells(2, ic + x).Value = sn_val(x)
wsReview.Cells(3, ic + x).Value = oper_val(x)
wsReview.Cells(4, ic + x).Value = dt_val(x)
'wsReview.Cells(5, ic + x).Value = tm_val(x)
Wend 'end rows
wsExport.Activate
ActiveWorkbook.Close
wsReview.Activate
usl_d = wsReview.Range("J11").FormulaR1C1
lsl_d = wsReview.Range("K11").FormulaR1C1
max_d = wsReview.Range("L11").FormulaR1C1
min_d = wsReview.Range("M11").FormulaR1C1
rng_d = wsReview.Range("N11").FormulaR1C1
ptu_d = wsReview.Range("O11").FormulaR1C1
std_d = wsReview.Range("P11").FormulaR1C1
avg_d = wsReview.Range("Q11").FormulaR1C1
cpk_d = wsReview.Range("R11").FormulaR1C1
wsReview.Range(wsReview.Cells(11, 10), wsReview.Cells(lastc + ir - csvdata_start, 10)).FormulaR1C1 = Format(usl_d, "0.0000")
wsReview.Range(wsReview.Cells(11, 11), wsReview.Cells(lastc + ir - csvdata_start, 11)).FormulaR1C1 = Format(lsl_d, "0.0000")
wsReview.Range(wsReview.Cells(11, 12), wsReview.Cells(lastc + ir - csvdata_start, 12)).FormulaR1C1 = Format(max_d, "0.0000")
wsReview.Range(wsReview.Cells(11, 13), wsReview.Cells(lastc + ir - csvdata_start, 13)).FormulaR1C1 = Format(min_d, "0.0000")
wsReview.Range(wsReview.Cells(11, 14), wsReview.Cells(lastc + ir - csvdata_start, 14)).FormulaR1C1 = Format(rng_d, "0.0000")
wsReview.Range(wsReview.Cells(11, 15), wsReview.Cells(lastc + ir - csvdata_start, 15)).FormulaR1C1 = ptu_d
wsReview.Range(wsReview.Cells(11, 16), wsReview.Cells(lastc + ir - csvdata_start, 16)).FormulaR1C1 = Format(std_d, "0.0000")
wsReview.Range(wsReview.Cells(11, 17), wsReview.Cells(lastc + ir - csvdata_start, 17)).FormulaR1C1 = Format(avg_d, "0.0000")
wsReview.Range(wsReview.Cells(11, 18), wsReview.Cells(lastc + ir - csvdata_start, 18)).FormulaR1C1 = Format(cpk_d, "0.0000")
'Generate dropdown list along row 9
wsReview.Range(Cells(9, 20), Cells(9, ic + lastr)).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=$A$1"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
i = 0
wsReview.Activate
For i = 1 To lastr
wsReview.Cells(1, ic + i).Value = i 'fills ID_Order
Next i
For i = 1 To (lastc - csvdata_start)
wsReview.Cells(ir + i, 1).Value = i ' fills CH_Order
Next i
wsReview.Range(wsReview.Cells(1, 1), wsReview.Cells(ir + lastc - csvdata_start, lastr + ic)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlDot
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
wsReview.Range(wsReview.Cells(10, 1), wsReview.Cells(10, lastr + ic)).Select
Selection.AutoFilter
ActiveSheet.UsedRange.Columns.AutoFit
ActiveSheet.Columns("A:AAA").HorizontalAlignment = xlCenter
ActiveWorkbook.SaveAs Filename:=f_title
Range("A11").Select
With Application
.ScreenUpdating = True
.DisplayAlerts = True
iWindowState = .WindowState
.WindowState = xlMaximized
End With
End Sub