VBA Question Multiply vs' replace

G

Guest

I got some help on this topic in an earlier post, but it is more complicated
that I had expected at first. Don Guillett was able to help, hoping to get
that last piece of the puzzle. Here is a link to the previous post:
http://www.microsoft.com/office/com...4d8f33-b837-445f-9f66-1aebcd3ad27b&sloc=en-us

In the previous post I needed to replace infomation including quantities,
the complcation is that sometimes the components occur more than just
quantity of 1. The master line should multiply with the componet line in
these cases.

Below is an example (trim line is the multiple example).

What I have now:
ColA ColB ColC ColD
1 Starter Open Type
3 XFMR Dry Type
AAA 4 Panelboard Type B
1 Box
2 Trim
BBB 2 Panelboard Type Q
1 Box
2 Trim
1 Ground Bar

What I need to end up with:
ColA ColB ColC ColD
1 Starter Open Type
3 XFMR Dry Type
AAA 4 Panelboard Type B
AAA 4 Box
AAA 8 Trim
BBB 2 Panelboard Type Q
BBB 2 Box
BBB 4 Trim
BBB 2 Ground Bar

The code Don provided me with is as follows, if that helps.

Thanks in advance.

Sub fillinblanksN()
lr = Cells(Rows.Count, "c").End(xlUp).Row
For Each c In Range("d2:d" & lr)
If Len(c) < 2 Then
c.Offset(0, -3) = c.Offset(-1, -3)
c.Offset(0, -2) = c.Offset(-1, -2)
End If
Next
End Sub
 
T

Tom Ogilvy

Sub fillinblanksN()
qty = 1
lr = Cells(Rows.Count, "c").End(xlUp).Row
For Each c In Range("d2:d" & lr)
If Len(c) < 2 Then
c.Offset(0, -3) = c.Offset(-1, -3)
c.Offset(0, -2) = c.Offset(0, -2) * qty
else
qty = c.offset(0,-2)
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top