Displaying a Range in a Message Box

FlashNZ

New Member
Joined
Mar 3, 2021
Messages
29
Office Version
  1. 365
Platform
  1. Windows
Hi, I found some code in a forum and it is working ok but I want to display the numbers in one column, they would ideally be all in a column where the two 12's are to the right in the pic.

Here is the code I am using:

VBA Code:
Sub DisplayUsage()

Worksheets("All Sales").Activate

MsgBox Join(Evaluate("TRANSPOSE(AA1:AA12 & """ & vbTab & """ & AC1:AC12)"), vbNewLine)

End Sub
 

Attachments

  • Capture.JPG
    Capture.JPG
    18.1 KB · Views: 1

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
 
Upvote 0
MsgBox is not well suited to displaying multi-column data so any solutions tend to look a bit kludgy. So for example, if the col AA data is always a month, this might work
VBA Code:
Sub DisplayUsage()
    Dim S As String, Ext As String, I As Long, VA
    Worksheets("All Sales").Activate
    
    VA = Split(Join(Evaluate("TRANSPOSE(AA1:AA12 & """ & vbTab & """ & AC1:AC12)"), vbTab), vbTab)
    For I = 0 To UBound(VA)
        Select Case I Mod 2
            Case 0
                Select Case UCase(VA(I))
                    Case "SEPTEMBER", "NOVEMBER", "DECEMBER"
                        Ext = vbTab
                    Case Else
                        Ext = vbTab & vbTab
                End Select
            Case 1
                Ext = vbCr
        End Select
        S = S & VA(I) & Ext
    Next I
    MsgBox S
End Sub

But if you come back and say that you were just using months as an example and it could be anything, then it probably won't. A better solution would be to create your own userform and use that instead of msgbox.
 
Upvote 0
Thanks, works perfectly and yes only using month.
 

Attachments

  • Capture.JPG
    Capture.JPG
    28.6 KB · Views: 0
Upvote 0
Another way :
VBA Code:
Sub DisplayUsage()
Dim a: a = [AA1:AA12]
Dim c: c = [AC1:AC12]
Dim i, str$
For i = LBound(a) To UBound(a)
    Select Case Left(a(i, 1), 1)
        Case "S", "N", "D": str = str & a(i, 1) & vbTab & c(i, 1) & vbCr
        Case Else: str = str & a(i, 1) & vbTab & vbTab & c(i, 1) & vbCr
    End Select
Next
MsgBox str
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,477
Messages
6,125,038
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