Dynamic row copy with condition

Hornet222

New Member
Joined
May 3, 2011
Messages
2
HI everyone,

I just got started with VBA and I have a challenging macro to program. I would appreciate if you could help me or give me a hint how to do the following.

I have a table that looks like this:

prices quantities Company
1 5 ABC Company
3 45 ABC Company
4 6 ABC Company
6 3 CDF Company
34 2 GHI Company
43 4 GHI Company

I would like to copy all rows (A1:C3) for ABC company in one worksheet, all rows for CDF in another worksheet and all rows for GHI company in a third worksheet. Here is the catch. Every week this table is updated and the names and frequence of the company change. For example in week two there is only one row for ABC company, no CDF company and 5 rows for GHI company. Is there any chance to code that in VBA?

I started and I created the following:

Sub Copy_data()

Workbooks("data 20110427.xls").Sheets("Refined data").Activate

If Range("C" + i) = Range("C" & (i + 1)) Then
Range("A" & i & ":C" & i).Select
Selection.Copy
Workbooks("M.xls").Activate
Range("A7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
Next
End Sub

However this setup far from complete and it would ignore the last row of every company.

Any ideas?

Thanks a lot!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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