Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top