I want to get msgbox the value of selected cells in a table.
Any hint how to do it?
Thanks.
Failed attempt. Thanks.Code:Dim Cell As Range
For Each Cell In Selection.Cells
MsgBox Cell.Cells.Value
Next
I want to get msgbox the value of selected cells in a table.
Any hint how to do it?
Thanks.
Failed attempt. Thanks.Code:Dim Cell As Range
For Each Cell In Selection.Cells
MsgBox Cell.Cells.Value
Next
You need
Code:Dim oCell As Cell
Dim oRng As Range
For Each oCell In Selection.Cells
Set oRng = oCell.Range 'Set a range to the cell
oRng.End = oRng.End - 1 'remove the cell end character from the range
MsgBox oRng.Text 'report the content
Next oCell
:bow::bow::bow:
I you want it reduced to a single message box:
Code:Sub ReturnCellText()
Dim strText As String
strText = Replace(Selection.Range.Text, Chr(13) & Chr(7) & Chr(13) & Chr(7), Chr(13) & Chr(7))
MsgBox Join(Split(strText, Chr(13) & Chr(7)), vbCr)
lbl_Exit:
Exit Sub
End Sub
Simpler, if there are no paragraph breaks in the cells:
This could be accumulated to a single output, too.Code:Dim Cell As Range
For Each Cell In Selection.Cells
MsgBox Split(Cell.Range.Text, vbCr)(0)
Next
Likewise simpler even if there are paragraph breaks in the cells:
Paul, did mean Dim oCell as Cell? As is, your code errors on the msgbox line.Code:Dim Cell As Cell
For Each Cell In Selection.Cells
MsgBox Split(Cell.Range.Text, Chr(7))(0)
Next
lbl_Exit:
Exit Sub