Question : Insert a string into a cell

Hi Expert,

I have a simple macro to insert a string into a cell of Excel worksheet. But it is not
working . I don't know what is wrong. I am new macro learner.

Thanks,
JT
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
For myRow = 0 To countArray - 2 Step 2
        Cells(lastRow, 4).Value = myDynArray(myRow)
        Cells(lastRow + 1, 4).Value = myDynArray(myRow + 1)
        lastRow = lastRow + 2
        
        
  Next myRow
Open in New Window Select All

Answer : Insert a string into a cell

Actually you can remove a ton of those Dims.  Use this
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
Public Sub BuildString()
 
   Dim Cell As Range
   Dim myLen As Integer
   Dim rowNums As String
   Dim firstLen As Integer
   Dim lastRow As Integer
 
 rowNums = InputBox("Please enter row numbers to copy")
 
 If rowNums = "" Then Exit Sub
 lastRow = CInt(rowNums)
 For Each Cell In Selection
     myLen = Len(Cell.Text)
         If (myLen > 250) Then
           firstLen = myLen / 2
           Cells(lastRow, 4).Value = Left(Cell.Text, myLen / 2)
           Cells(lastRow + 1, 4).Value = Mid(Cell.Text, firstLen + 1, myLen - firstLen)
           lastRow = lastRow + 2
         End If
 Next Cell
End Sub
Open in New Window Select All
Random Solutions  
 
programming4us programming4us