【发布时间】:2018-06-10 06:45:51
【问题描述】:
我对 VBA 非常陌生,正在尝试确定如何在一个单元格中存储多个值。比如我先:
- 扫描一行中的每个单元格以确定它是否为空白。 (A2:F3)
- 然后我确定了该空白单元格的列标题。 (A1:F1)
- 我创建了一个消息框,其中显示了相应列标题的单元格和标题。 (单元格为空。列标题为状态。)
我需要一些帮助来弄清楚:
- 如何循环以使每个列标题在保存到 G 列时不会覆盖下一个。
- 如何循环和连接以使一行中的多个列标题位于同一单元格中。 (例如,姓名、学校、州 - 这些将是我要拉到最后一列的标题。)
感谢您提供的任何帮助!
Sub EmptyCells()
Dim Cell As Range
Dim lrow As Long, i As Integer
Dim lcol As Long
Dim rw As Range
Dim reString As String
Dim ResultRng As Range
'Find the last non-blank cell in Column "School"
lrow = Cells(Rows.Count, 3).End(xlUp).Row
lcol = Cells(1, Columns.Count).End(xlToLeft).Column
MsgBox "Last Row: " & lrow
Set ResultRng = Range("G2:G3")
For Each rw In Sheets(1).Range("A1:F3").Rows
For Each Cell In rw.Cells
If IsEmpty(Cell.Value) Then
'MsgBox Cell.Address & " is empty. " & "The cell row number is " & Cell.Row & "." & vbNewLine & "The column header is " & Cell.Offset((1 - Cell.Row), 0)
ResultRng = Cell.Offset((1 - Cell.Row), 0)
End If
Next
Next
MsgBox "Complete"
End Sub
【问题讨论】:
标签: excel vba loops concatenation is-empty