Forum Discussion
Excel
Jan 02, 2022Iron Contributor
Import text file in VBA
Hello Everyone, I have written the code, after run the code it works well. But it always start from A1 I want to show start from D1. So, what should i add in VBA code? Please help...
- Jul 24, 2023
Select the cells with the dates.
On the Home tab of the ribbon, click Conditional Formatting > New Rule...
Select 'Format only cells that contain'.
Leave the first drop down set to 'Cell Value'.
Select 'less than or equal to' from the second drop down.
In the box next to it, enter the formula
=EDATE(TODAY(),-54)
If you use comma as decimal separator, change the formula to
=EDATE(TODAY();-54)
In Dutch:
=ZELFDE.DAG(VANDAAG();-54)
Click Format...
Activate the Fill tab.
Select orange.
Click OK, then click OK again.
Repeat these steps, but with the formula
=EDATE(TODAY(),-60)
or if you use comma as decimal separator
=EDATE(TODAY();-60)
and red as fill color.
HansVogelaar
Jan 02, 2022MVP
Public Sub ImportTextFile()
Dim CurFile As Workbook
Dim NewSheet As Worksheet
Dim TextFile As Workbook
Dim OpenFiles() As Variant
Dim i As Integer
Set CurFile = ActiveWorkbook
OpenFiles = GetFiles()
Application.ScreenUpdating = False
For i = 1 To UBound(OpenFiles)
Set NewSheet = CurFile.Worksheets.Add
Set TextFile = Workbooks.Open(OpenFiles(i))
TextFile.Sheets(1).Range("A1").CurrentRegion.Copy Destination:=NewSheet.Range("D1")
NewSheet.Name = TextFile.Name
Application.CutCopyMode = False
TextFile.Close
Next i
Application.ScreenUpdating = True
End Sub
Public Function GetFiles() As Variant
GetFiles = Application.GetOpenFilename(Title:="Select File(s) to Import", MultiSelect:=True)
End Function