Messagebox listing going down instead of across

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,913
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
The code below lists the address of all cells in a pre-defined range whose value is zero.

Rich (BB code):
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Dim Rng As Range
    
    With ws
    
        Set Rng = .Range(.Cells(1, 1), .Cells(1,1000))
    
    End With
    
    Dim ZeroColl As Collection
    Set ZeroColl = New Collection
    
    Dim RngElement As Range
    
    For Each RngElement In Rng
    
        If RngElement.Value = 0 Then ZeroColl.Add RngElement.Address
                    
    Next RngElement
    
    Dim ZeroCollCount As Long
    
    ZeroCollCount = ZeroColl.Count
    
    Dim i As Long
    
    Dim j As String
    
    For i = 1 To ZeroCollCount
    
        j = j & "," & ZeroColl(i)
    
    Next i
    
    Set Rng = Nothing
    
    Set RngElement = Nothing
    
    MsgBox " These cells are empty:" & vbNewLine & vbNewLine & Right(j, Len(j) - 1)


What I want is to have the message box display the addresses in a list going down, instead of in a single continuous sentence, ie I want:

Rich (BB code):
A20
A25
A33

instead of:

Rich (BB code):
A20, A25, A33

How can it be done?

Thanks


[/FONT]
 
Re: Messagebox listing going down instead of across (part 2)

If the message box is not a good idea, I suppose I can paste the results onto a worksheet instead.
I am thinking that might be a better option.
In order to clean up the data, they would need to close out of the Message Box, at which point, the list they need to use to identify which cells to clean up will be gone!
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Re: Messagebox listing going down instead of across (part 2)

I'd agree with Joe, putting it on a worksheet would be better.
How about
Code:
    Dim Rng As Range, RngElement As Range
    Dim i As Long
    With Ws
    
        Set Rng = .Range(.Cells(1, 1), .Cells(1, 1000))
    
    End With
    For Each RngElement In Rng
        If RngElement.Value = 0 Then
            i = i + 1
            Cells(i, 1).Value = RngElement.Address
        End If
    Next RngElement
 
Upvote 0
Re: Messagebox listing going down instead of across (part 2)

Thanks, that'll do nicely.
 
Upvote 0
Re: Messagebox listing going down instead of across (part 2)

Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

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