I want to get msgbox the value of selected cells in a table.
Any hint how to do it?
Thanks.
Failed attempt. Thanks.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.Dim Cell As Range For Each Cell In Selection.Cells MsgBox Cell.Cells.Value Next
You need
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
Graham Mayor - MS MVP (Word) 2002-2019
Visit my web site for more programming tips and ready made processes
http://www.gmayor.com
I you want it reduced to a single message box:
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.Dim Cell As Range For Each Cell In Selection.Cells MsgBox Split(Cell.Range.Text, vbCr)(0) Next
Cheers
Paul Edstein
[Fmr MS MVP - Word]
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.Dim Cell As Cell For Each Cell In Selection.Cells MsgBox Split(Cell.Range.Text, Chr(7))(0) Next lbl_Exit: Exit Sub