how show data in range by messagebox

Alaa mg

Active Member
Joined
May 29, 2021
Messages
343
Office Version
  1. 2019
hello
can anybody help me to show data are range by messagebox?
the range a1: f20 should show in message box
I try with this code but doesn't work correctly .
VBA Code:
Sub n()
Dim cell As Range
For Each cell In Range("a1:f20")
MsgBox "here is data " & cell
Next
End Sub
thanks
 
@rlv01 thanks again ! this is better , but is still not arranged.
may you see the picture,please?
1.PNG
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I will keep watching to see if there is a better answer. But a Message Box is not designed to show a range of data on a sheet perfectly as seen on the sheet but then maybe I will learn something more myself. If anything, I believe you maybe could have a script take a picture of the range and display the picture.
 
Upvote 0
But a Message Box is not designed to show a range of data on a sheet perfectly as seen on the sheet
I know . but may be there is way by writing some lines to fix this problem by making the spaces are equal especially the headers. I think the problem from the headers.
 
Upvote 0
@rlv01 thanks again ! this is better , but is still not arranged.
may you see the picture,please?
View attachment 65188
Posting pictures instead of data is part of the problem, since I would have to type in all the values manually if I wanted to experiment using your data. Instead you should be using the XL2BB add-in


so as not to require the people helping you to have to retype your data.

Book2
ABCDEFG
1cfttmbbttrefq
2aaaa1aaaa-100aaa00cf345
3aaaa1aaaa-100aaa00cf345
4aaaa1aaaa-100aaa00cf345
5aaaa1aaaa-100aaa00cf345
6aaaa1aaaa-100aaa00cf345
7aaaa1aaaa-100aaa00cf345
8aaaa1aaaa-100aaa00cf345
9aaaa1aaaa-100aaa00cf345
10aaaa1aaaa-100aaa00cf345
11aaaa1aaaa-100aaa00cf345
12aaaa1aaaa-100aaa00cf345
13aaaa1aaaa-100aaa00cf345
14aaaa1aaaa-100aaa00cf345
15aaaa1aaaa-100aaa00cf345
16aaaa1aaaa-100aaa00cf345
17aaaa1aaaa-100aaa00cf345
18aaaa1aaaa-100aaa00cf345
19aaaa1aaaa-100aaa00cf345
20aaaa1aaaa-100aaa00cf345
Sheet1
 
Upvote 0
Keep in mind that MsgBox is extremely limited in its ability to control text position and we have about reached the limit of what can be done.

VBA Code:
Sub n3()
    Dim cell As Range, RRng As Range
    Dim R As Range, CRng As Range, S As String

    Set RRng = Range("a1:f1")
    For Each cell In RRng
        If cell.Column = 3 Then
            S = S & cell.Value & Chr(9) & Chr(9)
        Else
            S = S & cell.Value & Chr(9)
        End If
    Next cell
    S = Application.Trim(S) & vbCr

    For Each cell In RRng
        If cell.Column = 3 Then
            S = S & "------" & Chr(9) & Chr(9)
        Else
            S = S & "------" & Chr(9)
        End If
    Next cell
    S = Application.Trim(S) & vbCr

    Set RRng = Range("a2:a20")
    For Each cell In RRng
        Set CRng = cell.Resize(1, 6)
        For Each R In CRng
            If R.Column = 3 Then
                S = S & R.Value & Chr(9) & Chr(9)
            Else
                S = S & R.Value & Chr(9)
            End If

        Next R
        S = S & vbCr
    Next cell
    S = Application.Trim(S)

    MsgBox "Here is the data in range " & RRng.Address & vbCr & vbCr & S, vbOKOnly
End Sub
 
Upvote 0
Solution
Posting pictures instead of data is part of the problem, since I would have to type in all the values manually if I wanted to experiment using your data. Instead you should be using the XL2BB add-in
sorry about it, but as you know to show the messagebox you need the picture to see the problem in messageox when show the data.
actually the last three columns still not arranged but I change this
VBA Code:
                S = S & R.Value & Chr(9) & Chr(9)
to
VBA Code:
                S = S & R.Value & Chr(9)
it's become arranging .
thanks for your time and efforts ;)
 
Upvote 0

Forum statistics

Threads
1,215,475
Messages
6,125,028
Members
449,205
Latest member
Eggy66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top