Như tui viết ở trên, tui có 1 macro tui viết cũng lâu lâu rồi, tìm chưa ra. Bạn thử dùng cái này xem sao. Macro này không dùng được cho 1 cột hay 1 hàng mà dùng cho cả table:
Code:
Sub macro()
Dim rngFirstSrc As Range
Dim rngLastSrc As Range
Dim intDestCol As Integer
Dim intDestRow As Integer
Dim rngCell As Range
Dim blnFirst As Boolean
'set flag for First address
blnFirst = True
'Get first cell in range
Set rngFirstSrc = ActiveCell
'find last entry in column
Set rngLastSrc = Cells(65534, ActiveCell.Column).End(xlUp)
'set first destination column
intDestCol = 1
'set first destination row
intDestRow = 1
'loop through all source cells
For Each rngCell In Range(rngFirstSrc, rngLastSrc)
'only do something if the source cell is not empty
If rngCell.Value <> "" Then
'test if there is a number in the cell, and its not the first address found
If IsNumeric(rngCell.Value) And blnFirst = False Then
'then test that it is less than 1000
If rngCell.Value < 1000 Then
'go to next row in destination
intDestRow = intDestRow + 1
'reset column counter
intDestCol = 1
End If
ElseIf IsNumeric(rngCell.Value) And rngCell.Value < 1000 Then
'change first address flag when first number <1000 found
blnFirst = False
End If
'copy cell contents
'but first see if it contains 'Tel'
If InStr(1, rngCell.Text, "Tel") = 0 Then
'if Tel is not in the text copy all the data in the cell
Worksheets("Sheet2").Cells(intDestRow, intDestCol).Value = rngCell.Value
Else
'copy the data as two items with Tel.No. in next column
Worksheets("Sheet2").Cells(intDestRow, intDestCol).Value = _
Left(rngCell.Text, InStr(1, rngCell.Text, "Tel") - 1)
'increment column counter
intDestCol = intDestCol + 1
Worksheets("Sheet2").Cells(intDestRow, intDestCol).Value = _
Right(rngCell.Text, Len(rngCell.Text) - InStr(1, rngCell.Text, "Tel") + 1)
End If
'increment column counter
intDestCol = intDestCol + 1
End If
Next rngCell
End Sub
Bạn phải thay đổi chút xíu cho phù hợp với file của bạn.