Hi all,
I wrote a code that open log file, find specific data from rows and after that delete all blank & error cell and copy all filter data.
what I try to do is to copy 20 last rows after filter the log file .
problem: row number is randomly according to log file but its always be the last 20 rows
*I have few log files and in each log rows number are different
I wrote a code that open log file, find specific data from rows and after that delete all blank & error cell and copy all filter data.
what I try to do is to copy 20 last rows after filter the log file .
problem: row number is randomly according to log file but its always be the last 20 rows
*I have few log files and in each log rows number are different
Rich (BB code):
Sub RectangleRoundedCorners1_Click()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Dim Y_Laser_factor As Range
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename(Title:="Browse for your File & Import Range", FileFilter:="Excel Files (*.log*),*log*")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets(1).Range("A1:B99999").Copy
ThisWorkbook.Worksheets("Main_0").Range("A1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
OpenBook.Close False
'Y counts from Stage'
Range("N2").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(LEFT(MID(RC[-13],FIND("" Y :"", RC[-13])+4,LEN(RC[-13])),FIND(""("",MID(RC[-13],FIND("" Y :"",RC[-13])+4,LEN(RC[-13])))-1),"""")"
Range("N2").Select
Selection.AutoFill Destination:=Range("N2:N150000"), Type:=xlFillDefault
Range("N2:N150000").Select
'Y Laser Factor'
Range("O2").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(LEFT(MID(RC[-14],FIND(""Y laser :"",RC[-14])+9,LEN(RC[-14])),FIND("","",MID(RC[-14],FIND(""Y laser :"",RC[-14])+9,LEN(RC[-14])))-1),"""")"
Range("O2").Select
'filter without blank & #value! rows'
Selection.AutoFill Destination:=Range("O2:O150000")
Range("O2:O150000").Select
Columns("N:N").Select
Selection.AutoFilter
ActiveSheet.Range("$N$1:$N$100162").AutoFilter Field:=1, Criteria1:="<>", Operator:=xlAnd, Criteria2:="<>#VALUE!"
ActiveSheet.Range("$N$2:$O$100162").SpecialCells(xlCellTypeVisible).Copy Destination:=ThisWorkbook.Worksheets("Y Laser Factor").Range("B4")
Worksheets("Y Laser Factor").Range("O2").Formula = "=IFERROR(Average(D4:D23),"""")"
End If
Application.ScreenUpdating = True
Worksheets(ActiveSheet.Index - 1).Select
Range("O2").Select
Selection.Copy
Range("D24").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False