Originally posted this by mistake in the classic VBA forum a few weeks ago and haven't received any responses... still looking for any help. Thanks.

I have just started trying to program some macros for Excel. I am trying to change the code for a program I have. The current version will take a string of characters in a single cell in Excel such as "ABCDEFG" and put each letter in its own cell. I want to adapt this to three letters in each cell such as it will put "ABC" in one cell and "DEF" in another.

Here is my code so far:


VB Code:
  1. Dim Words() As String
  2.     Dim cell As Range, rng As Range, ans As Variant, rowformat As Variant, rng1 As Variant
  3.     Dim i As Integer, k As Integer, N As Integer, L As Integer
  4.    
  5.     ans = MsgBox("place words in rows (Yes) or columns(No)?", vbYesNoCancel)
  6.     If ans = vbYes Then
  7.         rowformat = True
  8.     ElseIf ans = vbNo Then
  9.         rowformat = False
  10.     ElseIf ans = vbCancel Then
  11.         Exit Sub
  12.     End If
  13.    
  14.     Set rng = Selection
  15.     N = rng.Rows.Count
  16.     rng.NumberFormat = "@"
  17.    
  18.     For Each cell In rng
  19.         If Len(cell.Value) > L Then
  20.             L = Len(cell.Value)
  21.         End If
  22.     Next cell
  23.    
  24.     ReDim Words(1 To N, 1 To L)
  25.     For k = 1 To N
  26.         For i = 1 To L Step 3
  27.             Words(k, i) = UCase(Mid(rng.Cells(k), i, 3))
  28.         Next i
  29.     Next k
  30.    
  31. 10  If rowformat Then
  32.         On Error GoTo errorhandler
  33.         Set rng1 = rng.Range(Cells(1, 1), Cells(N, L))
  34.         rng1.Value = Words
  35.     Else
  36.         Set rng1 = rng.Range(Cells(1, 1), Cells(L, N))
  37.         rng1.Value = Application.WorksheetFunction.Transpose(Words)
  38.     End If
  39.     rng1.NumberFormat = "@"
  40.    
  41.     Exit Sub
  42. errorhandler:
  43.     ans = MsgBox("string too long - column format?", vbYesNo)
  44.     If ans = vbYes Then
  45.         rowformat = False
  46.         GoTo 10
  47.     Else
  48.         Exit Sub
  49.     End If
  50.    
  51. End Sub
I just added the "Step 3" to get what I want, but the problem is that the output is also skipping 3 lines and I have two blank cells in between my ouput. How can I get rid of these blank cells? Thanks for all help in advance!

Matt