show data ranges dynamically on the msgbox based on condition

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,489
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hello
i need the code it shows the data from a2:e of course dynamic on msgbox based on condition in column e is date if e=date+10 then show the data relating this date
i try with this code but not dynamic it's specific range and i stuck how i write the condition more over this code shows all of data
VBA Code:
Sub mesage()

    Dim xRg As Range

    Dim xTxt As String

    Dim xCell As Range

    Dim xStr As String

    Dim xRow As Long

    Dim xCol As Long

    On Error Resume Next

    If ActiveWindow.RangeSelection.Count > 1 Then

      xTxt = ActiveWindow.RangeSelection.AddressLocal

    Else

      xTxt = ActiveSheet.UsedRange.AddressLocal

    End If

    Set xRg = Range("a2:e10")

    If xRg Is Nothing Then Exit Sub

    On Error Resume Next

    For xRow = 1 To xRg.Rows.Count

        For xCol = 1 To xRg.Columns.Count

            xStr = xStr & xRg.Cells(xRow, xCol).Value & vbTab

        Next

        xStr = xStr & vbCrLf
    Next

    MsgBox xStr, vbInformation, "xrg"

End Sub
 
thanks GWTEB you're code works perfectly now it's useful two codes different to learn more i just would simple thing how can i show the header like dante's code
 
Last edited:
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
it's useful two codes different to learn more i just would simple thing how can i show the header like dante's code
Happy learning! As you see there are many ways to get what you're after. With the kind of approach I started with it could be like this.
VBA Code:
Sub Message()

    Dim xRg     As Range
    Dim xCell   As Range
    Dim xStr    As String
    Dim i       As Long

    Set xRg = Range("A2:E10")

    For Each xCell In xRg.Offset(-1, 0).Resize(1, xRg.Columns.Count)
        xStr = xStr & xCell.Value & vbTab
    Next
    xStr = xStr & vbCr & vbCr

    For Each xCell In xRg.Offset(0, 4).Resize(xRg.Rows.Count, 1)
        If xCell.Value = Date + 10 Then   '<<< in this line the condition is set related to Column "E:E"
            For i = -4 To 0 Step 1
                xStr = xStr & xCell.Offset(0, i).Value & vbTab
            Next i
            xStr = xStr & vbCrLf
        End If
    Next
    MsgBox xStr, vbInformation, "xRg"
    Set xRg = Nothing
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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