Today i am facing a problem...........i want to make many macro and try it on my Text file but nothing is going to right........
Below code i got from Recording Macro.........Below code including Text File opening + Set Break Line + Sort on COL-A and more more more................
i am looking for a solution, i want to make it dynamically......means that when i click on Commandbutton1, a open dialog box should be open like CTRL+O, where i choose my TextFile from my Desktop and it convert in Excel.........
Please see the excel file's Sheet Deletion
I am attaching 2files i.e. 1. TextFile and 2. Excel File, please see
Sub Macro4()
'
' Macro4 Macro
'
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\Gyan Verma\Desktop\July-2018 Advance\slgt0718.prn", Destination _
:=Range("$A$1"))
.CommandType = 0
.Name = "slgt0718"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(8, 10, 8, 20, 25, 7)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Cells.Select
ActiveWorkbook.Worksheets("Sheet4").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet4").Sort.SortFields.Add Key:=Range("A1:A122") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet4").Sort
.SetRange Range("A1:G122")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWindow.SmallScroll Down:=48
Rows("50:50").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Selection.End(xlUp).Select
Selection.End(xlUp).Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1").Select
ActiveCell.FormulaR1C1 = "S.No."
Range("B1").Select
ActiveCell.FormulaR1C1 = "Sheet_Code"
Range("C1").Select
ActiveCell.FormulaR1C1 = "E_Code"
Range("D1").Select
ActiveCell.FormulaR1C1 = "E_Name"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Designation"
Range("F1").Select
ActiveCell.FormulaR1C1 = "AMT"
Range("G1").Select
ActiveCell.FormulaR1C1 = "Department"
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Font.Bold = True
Cells.Select
Cells.EntireColumn.AutoFit
Selection.End(xlToLeft).Select
Selection.End(xlUp).Select
Sheets("Sheet4").Select
Sheets("Sheet4").Name = "Deletion"
End Sub
Bookmarks