Home > Software engineering >  Vba programming, inside the cell than the number of words automatically jump to the next cell
Vba programming, inside the cell than the number of words automatically jump to the next cell

Time:03-03

Want ten words within the cell can only input, but turn to the next cell exceeds the number of words

CodePudding user response:

Code:
 
Private mblnUpdating As Boolean

Private Sub Worksheet_Change (ByVal Target As Range)
If mblnUpdating Then
The Exit Sub
End the If

MblnUpdating=True

Dim strContent As String
StrContent=Target. The Text

Dim strTemp As String
For I=1 To Len (strContent)
StrTemp=strTemp & amp; Mid (strContent, I, 1)

If I Mod 10=0 Then
SetCellValue Target. The Row, and the Target. The Column + (I \ 10) - 1, strTemp
StrTemp=""
End the If
Next
If strTemp & lt;> "" Then
SetCellValue Target. The Row, and the Target. The Column + ((I - 1) \ 10), strTemp
End the If

MblnUpdating=False
End Sub

Private Sub SetCellValue (ByVal intRow As an Integer, ByVal intColumn As an Integer, ByVal strValue As String)
Dim objRange As Range
The Set objRange=Cells (intRow intColumn)
ObjRange. NumberFormatLocal="@"
ObjRange=strValue
End Sub

Run the example:


Download address:
Link: https://pan.baidu.com/s/1WB_W0ph6-JTUcy6KQ3EXBQ
The extracted code: DRTK
  •  Tags:  
  • VBA
  • Related