我正在尝试在 Excel 中编写一个宏来格式化和复制当前选择。作为其中的一部分,我想遍历所有单元格以有条件地对其行进行格式化(第一行略有不同)。对我来说最有意义的是“Rows()”,但它在 For Each 循环中返回不匹配错误。有什么想法可以解决这个问题吗?(此外,它应该根据选择将行数作为变量使用,现在我只是尝试使用 1-4。)
Sub Convert()
Dim sOutput As String
Dim rSelection As Range
Dim rCell As Range
Dim rHead As Range
Set rSelection = Selection.Cells
Set rHead = rSelection.Rows(1)
sOutput = "||"
For Each rCell In rHead
sOutput = sOutput & rCell.Value & "||"
Next rCell
sOutput = sOutput & Chr(10) & "|"
For Each rCell In rSelection.Rows(2)
sOutput = sOutput & rCell.Value & "|"
Next rCell
'sOutput = sOutput & Chr(10) & "|"
For Each rCell In rSelection.Rows(3)
sOutput = sOutput & rCell.Value & "|"
Next rCell
'sOutput = sOutput & Chr(10) & "|"
For Each rCell In rSelection.Rows(4)
sOutput = sOutput & rCell.Value & "|"
Next rCell
fCopy (sOutput)
MsgBox "Table has been copied and formatted."
End Sub
谢谢!