Excel如何在一列

时间:2018-06-12 18:30:19

标签: excel excel-vba vlookup vba

我目前有一个非常大的数据集,我正在尝试重新组织它们,如下所述:

电流:

A

C

(这里是空行)

A

C

d

这里空行

A

C

A列中有ABC或ABCD,后面是空行

我试图像这样格式化

ABC

ABCD

ABC ...

如果有人可以帮助我,我无法弄清楚如何做到这一点,这一切都在excel上完成

1 个答案:

答案 0 :(得分:0)

您的起点(摘自:Excel VBA, capture first "start" value and last "end" value per group

 Dim a as Long, b as Long, i as Long, lr as Long
 lr = cells(rows.count,1).end(xlup).row
 For i = 2 to lr
     If cells(i,1).value = cells(i+1,1).value then
          If a = 0 then
              a = i + 1
          End If
     Else
          If a > 0 AND b = 0 then
              b = i + 1
          End If             
     End If
     If b > 0 AND a > 0 Then
         'perform action on range(cells(a,2),cells(b,2))), etc.
         a = 0 'resets for next grouping
         b = 0 'resets for next grouping
    End If
Next i
a = 0
b = 0