VBA code to copy from one cell to another - causing error after 34000 working lines

chokfull

New Member
Joined
Sep 3, 2017
Messages
5
Here's a debug screenshot: http://i.imgur.com/HT3mFXy.png?1

The error (Application-defined or object-defined error) occurs at the highlighted breakpoint. This code works for every instance before this, but breaks at i = 34640 and check = 5519.

The cells are both valid, and they're listed in the Watch field. I can't fathom why this is occurring. I'm up late and tired, and hoping I just mistyped something, but I can't figure it out for the life of me.

Here's a quick code snippet producing the same error, under essentially the same conditions:

Code:
Sub test()
Dim wkbk As String, checkWkbk As String
Dim check As Long, i As Long
wkbk = "dump1.csv"
checkWkbk = wkbk
i = 34640
check = 5519
Workbooks(wkbk).Sheets(1).Cells(i, 7).Value = Workbooks(checkWkbk).Sheets(1).Cells(check, 6).Value
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I don't think that's the issue. It was working previously, and I'm using the csv format because I'm going to be porting this into another program later. If the csv format is the issue, I'd love a workaround.
 
Upvote 0
I'm having similar issues on another worksheet as well (same format). This time it breaks at 49592. I also tried switching to .xlsx format instead of .csv, no dice. This is really bugging me, any ideas? The full code's much simpler this time:

Code:
Sub finder()
Dim target As String




For i = 49592 To 1000000
    target = Cells(i, 3).Value
    j = 1
    Do While j < 25 And (i - j) > 0
        If Cells(i - j, 2).Value = target Then
            Cells(i, 7).Value = Cells(i - j, 6).Value
            j = 25
        End If
        
        j = j + 1
    Loop
Next i
End Sub

It just loops through, looking for matches, then copying them over. I don't have any int variables declared, so I don't think it's an overflow problem.
 
Upvote 0
Side note: I did notice the text starts with an emoticon in both cases, so I thought it might be trying to read a formula, despite them being enclosed in quotes. I tried adding extra text to the beginning to throw that off, but again, no dice. This is driving me crazy!
 
Upvote 0
No, my mistake, I think the emoticons are the exact problems. They use the = sign for eyes, so it's trying to read the text as a formula when I copy it over. Does anyone have a workaround for that?
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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