using loops and dynamic cell references to copy selective rows of data

prinjas

New Member
Joined
Jan 19, 2011
Messages
1
Gday all,

I've been trying my hand at writing a macro to compile data from two separate sheets, I've gotten a lot of more simple stuff to work but the macro i've created to copy selective rows of data into a new sheet seems to do nothing.

I figure i've probably got some usage/ syntax way off, any errors you can see/ ways to simplify or improve the code would be greatly appreciated.

The premise is that i have an entire month of time usage data for our equipment, night and day shifts, and i also have production data for the month, but the production data is only present for those days/shifts that were active, so its not possible to just line up a copy and paste.
Columns A is the equipment's name
Column B is the date
Column C is the shift
Column D through F is the desired data to be copied.

The code in question is:

Dim prodrow
Dim exportrow
prodrow = 2
exportrow = 3

Do While prodrow < 162

Do While exportrow < 473
Sheets("Export").Select
If Range("A" & exportrow) = Sheets("prod").Range("A" & prodrow) Then
MsgBox "Column A Matches"

If Range("B" & exportrow) = Sheets("prod").Range("B" & prodrow) Then
MsgBox "Column B Matches"

If Range("C" & exportrow) = Sheets("prod").Range("C" & prodrow) Then
MsgBox "Column C Matches"

Sheets("prod").Select
Range("D" & prodrow : "F" & prodrow).Select
Selection.Copy
Sheets("EXPORT").Select
Range("D" & exportrow).Select
ActiveSheet.Paste
prodrow = prodrow + 1
exportrow = 3

Else: exportrow = exportrow + 1
End If

Else: exportrow = exportrow + 1
End If

Else: exportrow = exportrow + 1
End If
Exit Do
Loop
Exit Do

Loop

Once again, any help would be greatly appreciated.

Cheers,
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,215,084
Messages
6,123,024
Members
449,092
Latest member
ikke

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