MsgBox - Dynamic Range

Nordicrx8

Board Regular
Joined
Dec 10, 2015
Messages
143
Office Version
  1. 365
Platform
  1. Windows
Hey all!

I'm using a MSG Box to display values from a range of cells. The below code is working, but the range actually needs to be dynamic.

There is a formula in H2-H400 doing a lookup. A value (That I want to display in the MsgBox) will only appear in this range if the user updates the workbook. If no changes are made, the values in column H will have a zero in it.

Ideally, I'd like it to identify what cells in the range have a zero in them, and omit them from the values printed in the MsgBox.

As another option, I wrote a formula in i1 & J1 (on sheet "Verify") that automatically update to correct range - we could do an indirect to those cells.

Been struggling on getting either of these options working and wanted to reach out for a helping hand.

Thanks all!

VBA Code:
Sub VER_Bulk()

Set Rng = Sheets("Verify").Range("H1:H7")

For Row = 2 To Rng.Rows.Count
For col = 1 To Rng.Columns.Count

Values = Values & Rng.Cells(Row, col).Value _
& vbTab & vbTab
Next col
Values = Values & vbNewLine
Next Row

MsgBox "Updates have been made to the following zones: " _
& vbLf & vbLf & Values
End Sub
 
Last edited:

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Perhaps the below will help:
VBA Code:
Sub VER_Bulk()
    Dim rng As Range, sValues As Variant, rngAddr As String

    Set rng = Sheets("Verify").Range("H1:H7")
    rngAddr = rng.Address(, , , True)
    sValues = Evaluate("FILTER(" & rngAddr & "," & rngAddr & "<>0)")
    
    MsgBox "Updates have been made to the following zones: " _
        & vbNewLine & vbNewLine & Join(Application.Transpose(sValues), vbNewLine)
End Sub
 
Upvote 0
Solution
Perhaps the below will help:
VBA Code:
Sub VER_Bulk()
    Dim rng As Range, sValues As Variant, rngAddr As String

    Set rng = Sheets("Verify").Range("H1:H7")
    rngAddr = rng.Address(, , , True)
    sValues = Evaluate("FILTER(" & rngAddr & "," & rngAddr & "<>0)")
   
    MsgBox "Updates have been made to the following zones: " _
        & vbNewLine & vbNewLine & Join(Application.Transpose(sValues), vbNewLine)
End Sub
Works Perfectly! Thanks so much! Now I am thinking about displaying two columns of data, using the same criteria. (H1:i10) I tried making the change, but it broke it. anything special I need to add in for it to display two columns? thanks again for your help!!
 
Upvote 0
Are you trying to have the value in column I be displayed next to the value in column H in the message box?
Can column I have a value other than 0 as well as column H?
If column H has a 0 should it omit column I for that row?
 
Upvote 0
Are you trying to have the value in column I be displayed next to the value in column H in the message box?
Can column I have a value other than 0 as well as column H?
If column H has a 0 should it omit column I for that row?
Yes, have them side by side. I was going to have them be a separate message box, but I think It makes more sense to just have the two columns with a header. (same conditions, if zero, do not show) They they both will hold different values, but always be text.
 
Upvote 0
Maybe the below:
VBA Code:
Sub VER_Bulk()
    Dim sValues As Variant
    Dim rng As Range, cRng As Range
    Dim rngAddr As String, cRngAddr As String

    Set rng = Sheets("Verify").Range("H1:I7")
    Set cRng = Sheets("Verify").Range("H1:H7")
    
    rngAddr = rng.Address(, , , True)
    cRngAddr = cRng.Address(, , , True)

    sValues = Evaluate("BYROW(FILTER(" & rngAddr & "," & cRngAddr & "<>0),LAMBDA(x,TEXTJOIN("" "",,x)))")
    
    MsgBox "Updates have been made to the following zones: " _
        & vbNewLine & vbNewLine & Join(Application.Transpose(sValues), vbNewLine)
End Sub
 
Upvote 0
Yes! That worked! Totally not following the code as it's way over my head (will have to google some of it later to figure out what some of this code does) but my hat is off to you on writing this without seeing my workbook, and for doing it at 2AM!

Any way we could clean up the display of the content to make it look more like the source data? (alignment)

Thanks again for all your help!


1692977219790.png

Capture3.PNG
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,951
Members
449,095
Latest member
nmaske

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