Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a workbook with two worksheets on it. Worksheet "Sheet2" has the new months data and worksheet "Audit scores" is the sheet that I am copying the data to. The code I wrote is suppose to check for the equipment name in "Sheet2" Column c and find the matching one in "Audit scores" then copy the value from the Sheet2 column e and paste it into the last column in the appropriate row on Audit scores. The issue that I'm having is that the value being pasted in "Audit scores" is not the correct value from "Sheet2". Hopefully the mistake is a simple one and i'm just blind to it.

Here's the code:

Sub newdata()

Dim x As Variant, y As Long, z As Long, v As Date

LRow = Cells(Rows.Count, 2).End(xlUp).Row
Lcol = Cells(3, Columns.Count).End(xlToLeft).Column
v = Date
Worksheets("Audit scores").Activate
Cells(1, Lcol + 1).EntireColumn.Insert
Cells(1, Lcol + 1).Value = v
For y = 1 To LRow
    For z = 1 To LRow
        If Cells(z, "C").Value = Worksheets("Audit scores").Cells(y, "C").Value Then
            Worksheets("Sheet2").Cells(z, "E").Copy Destination:=Worksheets("Audit scores").Cells(y, Lcol + 1)
        Else:
        End If
    Next z
Next y
End Sub

Thanks for any help you can give me.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

you have activated Audit scores, but your check does not check back against Sheet2.

If Cells(z, "C").Value = Worksheets("Audit scores").Cells(y, "C").Value Then

should be

If Worksheets("Sheet2").Cells(z, "C").Value = _
     Worksheets("Audit scores").Cells(y, "C").Value Then

(split onto 2 lines for readability)

share|improve this answer
 
Thanks for the help, that fixed everything. I figured it was some simple mistake on my part that caused the entire sheet to be off. –  meverhart913 Jul 18 '13 at 17:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.