Hello and this is my first post. I have a need to import text files into excel format and then save. I have the following code written, some borrowed and everything works fine when I step through the vba using F8. When I run it however, the code not only highlights my last row but it also highlights the row 13. I only need the last row highlighted. Where have I gone wrong?
Here's my code (sorry, I can't download HTML maker on my work PC)
Joe
Here's my code (sorry, I can't download HTML maker on my work PC)
Code:
Sub CDS_Detail_Report()
Application.ScreenUpdating = False
Dim sPath As String, sDir As String
Dim ws As Worksheet
Dim i As Long
Dim LRow As Long, lCol As Long
Dim rng As Range
sPath = "C:\Users\jpprespa\Desktop\Format\"
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
sDir = Dir$(sPath & "*.txt", vbNormal)
Do Until Len(sDir) = 0
Workbooks.Open (sPath & sDir)
ActiveSheet.Name = "Detail"
Range("A1:L10").Select
With Selection.Interior
.ThemeColor = xlThemeColorLight2
.TintAndShade = 0.8
End With
Range("A11:L12").Select
With Selection.Interior
.ThemeColor = xlThemeColorAccent3
End With
Range("A11:L11").Select
Selection.Font.Bold = True
Range("A12").Select
Selection.Font.Bold = True
Range("K:K").NumberFormat = "#,##0"
Range("L:L").NumberFormat = "$#,##0.00"
Columns("A:L").EntireColumn.AutoFit
Set ws = Sheets("Detail")
With ActiveSheet
LRow = .Cells(.Rows.Count, 1).End(xlUp).Row
lCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With
For i = LRow To 2 Step -1
If Cells(i, 1) <> Cells(i - 1, 1) Then
Range(Cells(i, "L"), Cells(i, lCol)).Interior.ThemeColor = xlThemeColorAccent3
End If
Next i
With ActiveWorkbook
.SaveAs FileName:=Left(.FullName, InStrRev(.FullName, ".")) & "xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
.Close
End With
sDir = Dir$
Loop
Application.ScreenUpdating = True
End Sub
Joe
Last edited by a moderator: