troubleshooting Question

VBA copy down rows

Avatar of Euro5
Euro5Flag for United States of America asked on
VBAMicrosoft ExcelMicrosoft Office
7 Comments1 Solution16 ViewsLast Modified:
New Sample.xlsx 

I have to copy down rows in a way very similar to the previous code that copies down columns A & B.
For this project, I need to do the same with columns A, B, C D in the same way.
D copies down until not empty or C changed.
C copies down until not empty or B changed.
B copies down until not empty or A changed.
A copies down until not empty OR until K is empty.

The sample file shows the original from A - E  and what it should look like completed is F - K.
Please - can anyone help?! Thank you!
Sub Filldownrows()
    Worksheets("Sheet1").Activate
Dim lngLastRow As Long
Dim lngRow As Long
Dim strSubcat As String
Dim strCat As String

With ActiveSheet
    strCat = .Range("A2")
    strSubcat = .Range("B2")
    lngLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
    For lngRow = 3 To lngLastRow
        If Not IsEmpty(.Cells(lngRow, "A")) Then
            If .Cells(lngRow, "A") <> strCat Then
                strCat = .Cells(lngRow, "A")
                strSubcat = ""
            End If
        End If
        
        If IsEmpty(.Cells(lngRow, "B")) Then
            .Cells(lngRow, "A") = strCat
            .Cells(lngRow, "B") = strSubcat
        Else
            strSubcat = .Cells(lngRow, "B")
            .Cells(lngRow, "A") = strCat
        End If
    Next
End With
End Sub
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros