0

I would give a full description but everything relevant has already been said in this question from two years ago that went completely unresolved:

Writing a string to a cell in excel

My program is as simple as it can possibly be:

`Sub separate()
Dim stri As String
Dim i As Long
stri = Sheets("HEXDUMP").Cells(1, 5).Text
For i = 0 To (Len(stri) / 4)
    Sheets("HEXDUMP").Cells(i, 1).Value = Mid(stri, ((i * 2) + 1), 2)
    Sheets("HEXDUMP").Cells(i, 2).Value = Mid(stri, ((i * 2) + 3), 2)
Next i
End Sub`

All I want is to take a string and break it down into cells of two characters each. Of course everything works perfectly except it won't write to a cell no matter what you do to it. I tried unprotecting I tried .text I tried making a new sheet restarting you name it. It's a bug in excel and all I want at this point is a workaround.

Community
  • 1
  • 1

1 Answers1

1

You have an error in your code.

For i = 0, i.e. the first iteration of your loop, the following code will give an error:

... .Cells(i, 1) ...
... .Cells(i, 2) ...

as there's no row 0. Change it to:

... .Cells(i + 1, 1) ...
... .Cells(i + 1, 2) ...

and it will work. Not sure it's exactly what you want, but at least it won't give an error.

djikay
  • 10,450
  • 8
  • 41
  • 52
  • Fair enough that's my mistake. Why does it give you a "Application-defined or object-defined Error" message instead of something that would make any sense and lead one to the correct conclusion, like say "Subscript out of range" which seems to be for exactly this situation? And I still don't understand how the last guy encountered the same problem and found no solution. – user3897521 Jul 31 '14 at 23:17
  • 1
    @user3897521: I didn't downvote you, I actually tried to help you... – djikay Jul 31 '14 at 23:22