Excel Get All Multiples Of Column A & B If For Sim

2019-08-21 18:56发布

How Would you add a condition so the value of column B and C only repeat depending on value of column C.

Height Width Project
400    200   Alpha
500    300
700
800
1000    200   Beta
5000    900
6500    420
760
890

I am after something that's all multiples of column A & B for project alpha. Then all multiples of Column A & B for project Beta.

400    200   Alpha
500    200   Alpha
600    200   Alpha
700    200   Alpha
800    200   Alpha
400    300   Alpha
500    300   Alpha
600    300   Alpha
700    300   Alpha
800    300   Alpha
1000   200   Beta
5000   200   Beta
...

So far I have this sub that gives me all multiples of column A & B

    Sub loops()

Dim n_height, n_width, c As Integer

With ThisWorkbook.Sheets("Sheet1")

n_height = .Cells(Rows.Count, 1).End(xlUp).Row 'Assuming height is in column A
n_width = .Cells(Rows.Count, 2).End(xlUp).Row 'Assuming width is in column B

c = 2

For i = 2 To n_height
    For j = 2 To n_width
        .Range("D" & c).Value = .Range("A" & i).Value 'Prints heights in column D
        .Range("E" & c).Value = .Range("B" & j).Value 'Prints widths in column E
        c = c + 1
    Next j
Next i

End With

End Sub

I need a condition adding to this that value only repeat depending on column C value.

0条回答
登录 后发表回答