Houston, We've Had a Problem

J

John21

I'm getting a problem with this line of code, something about global
referense or something like that.......

Set RngColD = Range("D1", Range("D" & Rows.Count).End(xlUp))

the complete code is this....


Dim RngColD As Range
Dim i As Range
Dim Info As String
Set RngColD = Range("D1", Range("D" & Rows.Count).End(xlUp))
Info = ""
For Each i In RngColD
If i.Value = Range("A517").Value Then
If Info = "" Then
Info = i.Offset(, 20).Value
Else
Info = Info & "," & i.Offset(, 20).Value
End If
End If
Next i
Range("G517") = Info
Info = ""

End Sub
 
G

Guest

I see nothing distinctly wrong with what you have. Try being a little more
explicit in your referencing to the sheet perhaps. Something like this...

Dim RngColD As Range
Dim i As Range
Dim Info As String
Dim wks As Worksheet

set wks = ActiveSheet
with wks
Set RngColD = .Range(.Range("D1"), .Cells(Rows.Count, "D").End(xlUp))
end with

Info = ""
For Each i In RngColD
If i.Value = Range("A517").Value Then
If Info = "" Then
Info = i.Offset(, 20).Value
Else
Info = Info & "," & i.Offset(, 20).Value
End If
End If
Next i
Range("G517") = Info
Info = ""

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