Home > Mobile >  Fill down items in column A, based on items in column B (Only if column B has more than one item)
Fill down items in column A, based on items in column B (Only if column B has more than one item)

Time:02-05

I have logic set-up in my program where it does the following:

  1. After clicking a macro button, it generates 1 or more names in column B. In this example, let's say 2 names are generated after clicking the button: enter image description here

  2. My logic is set to where the name in column A fills down based on the last non-empty cell in column B. So, it does this: enter image description here

Here is my code that is working perfectly fine if there's more than one item in column B:

With AssetToolSheet
   n = .Cells(Rows.Count, "A").End(xlUp).Row
   lrowb = .Cells(Rows.Count, "B").End(xlUp).Row
   .Range("A" & n & ":A" & lrowb).FillDown
End With

Now, here's my issue. Sometimes, column B might only have one generated asset name.

  1. For example, let's say only one name is generated: enter image description here

  2. Since the code is set in place as shown above, it will still fill down even though there is no need to fill down column A (there's only one generated name in column B, so no need to fill down anything in column A). This is what it does: enter image description here

I want to prevent my code from filling down column A if there is only one generated asset name in column B. If there is more than one generated asset name in column B, my logic works perfectly fine.

Thanks!

CodePudding user response:

If colA max row = colB max row do nothing, else fill down.

    Sub Filldown()

Dim AssetToolSheet
Dim N As Integer
Dim lrowb As Integer
Set AssetToolSheet = Sheet1

With AssetToolSheet
    N = .Cells(Rows.Count, "A").End(xlUp).Row
    lrowb = .Cells(Rows.Count, "B").End(xlUp).Row
    If N <> lrowb Then
        .Range("A" & N & ":A" & lrowb).Filldown
    End If
End With

End Sub
  •  Tags:  
  • Related