[RESOLVED] Something weird is happening in excel (VBA)
Hi guys,
Got this code below where ws1/2/3 etc makes reference to my worksheet. All stuff is defined.
Code:
Dim i As Long
Dim RwCount1 As Long
RwCount1 = ws5.Range("F" & Rows.Count).End(xlUp).Row
For i = 2 To RwCount1
If ws5.Range("CG" & i).Value = "Unknown" Or "0" Then
ws5.Activate
ws5.Range("E" & i).Select
Selection.Copy
ws6.Activate
Range("J" & Rows.Count).End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
End If
Next i
Application.ScreenUpdating = True
End Sub
This macro looks through column CG and determines which have an "unknown" or "0" value assigned as the result of a formula. It then pastes the corresponding value of column E into a new sheet.
Now its doing this fine, but for some reason it is not taking in duplicate values, which is fantastic as it has saved me from writing the code to get rid of duplicates; but does anyone know why it is acting like this?
Thanks
Re: Something weird is happening in excel (VBA)
Which duplicates is it not "taking?" Values from column E?
Re: Something weird is happening in excel (VBA)
yeh, there are duplicate values in column E, but it seems to be only taking one instance.
This is fine, I was just wondering why it was doing this
1 Attachment(s)
Re: Something weird is happening in excel (VBA)
I've attached my version of this...can you step through and tell me if you see anything different than your version? I DO get dupes in mine...
Re: Something weird is happening in excel (VBA)
Quote:
If ws5.Range("CG" & i).Value = "Unknown" Or "0" Then
this is incorrect, should be
vb Code:
If ws5.Range("CG" & i).Value = "Unknown" Or ws5.Range("CG" & i).Value = "0" Then
i can not be sure what the difference in result should be
Re: Something weird is happening in excel (VBA)
vbfbryce - no problem on this one, dno whats going on then. Thanks for your help again!
westconn1 - thanks aswell, duly noted re the 'or' point