我有一堆带有大量数据的Excel图表
每隔几行都是空白
如果有一个空白行,我想连接A列中的单元格和下面一行中B列的最后4个字符,只要下面A列中的单元格不等于“。”
我有以下内容:
Sub Macro3()
'
' Macro3 Macro
'
'
For Each cell In Columns("A")
If ActiveCell.Value = "" Then ActiveCell.FormulaR1C1 = _
"=IF(R[1]C<>""."",CONCATENATE(R[1]C,RIGHT(R[1]C[1],4)),"""")"
Range("A2").Select
Next cell
End Sub
答案 0 :(得分:0)
cell
对象循环,那么为什么要使用ActiveCell
?我的建议是找到Col A中的最后一行,然后在确定实际范围时将其考虑在内,然后循环显示。
这是你在尝试的吗?
Sub Sample()
Dim aCell As Range
Dim lRow As Range
Dim ws As Worksheet
'~~> Change this to the relevant sheet name
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
'~~> Find Last row in col A which has data
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
'~~> Check each cell in the relevant range
For Each aCell In .Range("A1:A" & lRow)
If aCell.Value = "" Then _
aCell.FormulaR1C1 = "=IF(R[1]C<>""."",CONCATENATE(R[1]C,RIGHT(R[1]C[1],4)),"""")"
Next aCell
End With
End Sub