Format last row

jpprespa

New Member
Joined
Apr 10, 2013
Messages
8
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)
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:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top