我有很多3种语言的原始数据,其中大部分是在.xlsx
。 您可以考虑数据,因为表格包含3列和许多行(百万)。如何在Excel 2010中创建条件单元格合并?
我想建立其实现这个宏:
检查,如果你的相邻单元的单元是空的,合并到自己的上述细胞。
if (the cell on your left is empty):
merge yourself to the above cell;
我对VB没有什么了解,但是我想自己实现它,我该怎么做呢?
我有很多3种语言的原始数据,其中大部分是在.xlsx
。 您可以考虑数据,因为表格包含3列和许多行(百万)。如何在Excel 2010中创建条件单元格合并?
我想建立其实现这个宏:
检查,如果你的相邻单元的单元是空的,合并到自己的上述细胞。
if (the cell on your left is empty):
merge yourself to the above cell;
我对VB没有什么了解,但是我想自己实现它,我该怎么做呢?
没有更多的信息很难回答,但是这概括了一些问题。
你需要一个地方来存储感兴趣的单元格的行和列:
Dim ColCrnt As Long
Dim RowCrnt As Long
如果你想往下跑一栏,你可以写这样的:
ColCrnt = 5 ' 5 represents column "E". Columns are numbered from 1.
For RowCrnt = 1 to 1000
'Update code.
Next
如果您想要移动光标然后调用宏,您可以编写如下内容:
ColCrnt = ActiveCell.Column
RowCrnt = ActiveCell.Row
' Update Code.
假设更新代码是活动工作表上操作,这将是这样的:
If Cells(RowCrnt, ColCrnt - 1).Value = "" Then
Cells(RowCrnt-1, ColCrnt).Value = _
Cells(RowCrnt-1, ColCrnt).Value & Cells(RowCrnt-1, ColCrnt).Value
Cells(RowCrnt, ColCrnt).Value = ""
End If
Cells(RowCrnt, ColCrnt).Value
是当前单元的值。从RowCrnt中减1,引用上面的单元格。从ColCrnt减1,引用左边的单元格。
Cells(RowCrnt-1, ColCrnt).Value = Cells(RowCrnt-1, ColCrnt).Value & Cells(RowCrnt-1, ColCrnt).Value
将当前单元格的值连接到上面单元格的末尾。
Cells(RowCrnt, ColCrnt).Value = ""
清除当前单元格。
所以:
| E |
|---------|
| The |
| cat |
变为:
| E |
|---------|
| Thecat |
| |
如果你想之间 “的” 和 “猫” 的空间:
Cells(RowCrnt-1, ColCrnt).Value = _
Cells(RowCrnt-1, ColCrnt).Value & " " & Cells(RowCrnt-1, ColCrnt).Value
如果你想 “猫” 上一条新线::
Cells(RowCrnt-1, ColCrnt).Value = _
Cells(RowCrnt-1, ColCrnt).Value & vblf & Cells(RowCrnt-1, ColCrnt).Value
注意:单元格可能需要非常长的字符串,但只有开头才可见。
希望这能让你开始。