Reputation: 1050
I am using the code below to lookup some values from a different sheet. Each time i receive run-time error 13. I am unsure how to correct my data type. What's strange to me is that I do return the proper values, but not without receiving this error (which stops the rest of my code from running). Can you explain how I can correct this? Thanks!
Dim acs As Integer
For acs = 2 To 2000
Set rng1 = Sheets("RD" & y).Range("C" & acs)
Set rng2 = Sheets("RD" & y).Range("D" & acs)
Set rng3 = Sheets("RD" & y).Range("E" & acs)
If Sheets("Tsecond").Range("Y" & acs) = Sheets("inputs").Range("B" & y) Then
Sheets("Tsecond").Range("AE" & acs).Copy
Sheets("RD" & y).Range("C" & acs).Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("Tsecond").Range("AE" & acs).Copy
Sheets("RD" & y).Range("C" & acs).Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("Tsecond").Range("Y" & acs).Copy
Sheets("RD" & y).Activate
rng2.Select
ActiveSheet.Paste
Sheets("Tsecond").Range("T" & acs).Copy
Sheets("RD" & y).Activate
rng3.Select
ActiveSheet.Paste
End If
Application.ScreenUpdating = False
Next acs
Upvotes: 1
Views: 1597
Reputation: 26646
When I get a confusing error on one line of code, what I do is break the line down into multiple lines, by using simple assignments. Running these simple assignments and watching which one gets the error along with other debugging information sometimes sheds enough light to reveal the issue. For your line:
If Sheets("Tsecond").Range("Y" & acs) = Sheets("inputs").Range("B" & y) Then
what I'd do is something like this:
Set s1 = Sheets("Tsecond")
Let rc1 = "Y" & acs
Set r1 = s1.Range(rc1)
Set s2 = Sheets("inputs")
Let rc2 = "B" & y
Set r2 = s2.Range(rc2)
If r1 = r2 then
If an error appears before the If
, then the debugger should help you see what the various types of the broken down expressions are. If the error appears on the If
line, then change that to this:
Let v1 = r1.Value
Let v2 = r2.Value
if v1 = v2 then
The debugger should help show you what types v1 and v2 are (in case they are incompatible), or if there are other errors somehow (i.e. r2.Value represents multiple cells instead of a single value).
Perhaps this will give you some insight into the problem.
Upvotes: 2