根据单元格内容对单元格进行排序

时间:2017-06-07 08:35:06

标签: excel-vba isnumeric vba excel

enter image description here

我目前拥有的是客户的信息(姓名,地址,固定电话或手机号码),所有信息都在A栏中,中间有空白单元格,以及F& D列上每个客户的一些注释。 -G。

我要做的是将每个客户的相关信息移动到与名称相同的行(例如名称@ A1,然后地址@ B1,数字(如果固定电话)@ C1(否则@ C2))并组合客户的笔记到同一行的一个单元格中(F1 = F1& F2)。

我们正在谈论成千上万行和多个工作簿,所以这需要通过VBA来完成 请找到我到目前为止所尝试的内容:

Sub SORT()
' Keyboard Shortcut: Ctrl+Shift+M
Dim i As Long, j As Boolean
i = 1
j = IsNumeric(ActiveCell.Range("A1"))
Do
    If j = True Then    'Check if cell content is numeric
        If ActiveCell.Range("A1") < 3000000000# Then    'Then if it's a landline
            Selection.Cut
            ActiveCell.Offset(-3, 2).Range("A1").Select 'Put it in column C
            ActiveSheet.Paste
            ActiveCell.Offset(1, -2).Range("A1").Select 'Go to Address Cell
        Else
            Selection.Cut                   'If it is a mobile
            ActiveCell.Offset(-3, 3).Range("A1").Select 'Put it in column D
            ActiveSheet.Paste
            ActiveCell.Offset(1, -3).Range("A1").Select 'Go to Address Cell
        End If
        Selection.Cut                   
        ActiveCell.Offset(-1, 1).Range("A1").Select
        ActiveSheet.Paste                   'Put the Address to column B
        ActiveCell.Offset(4, -1).Range("A1").Select     'Go to next cell
        i = i + 4
    Else
        ActiveCell.Offset(1, 0).Range("A1").Select      'If Check if cell content is not numeric, go to next cell
        i = i + 1
    End If
Loop While i <= 100
End Sub

示例文件:https://www.dropbox.com/s/uf9yh6fnxl54j55/SAMPLE.xlsx?dl=0

0 个答案:

没有答案
相关问题