2

There are two columns. one has some names of tables and second one has its values.

Dim rng As Range
    Set rng = [AH3:AH50]  ' <-- adjust to your requirements    
    If Application.WorksheetFunction.Max(rng) > 95 Then    
    MsgBox "tables has sixe more than 95"    
End If   

Help required is:
1. Msgbox should also display the actual value of the cell it finds more than 95.
2. Also it should display the name of the corresponding table for which it is displaying the value in step one.

msgbox output should be:
"ABCD table has current size:96.6"

2 Answers 2

2

This code assumes the table names are in the column before the table values. Change the Offset parameter from -1 if that's not the case.

Sub TestRange()
    Dim rngValues As Range
    Dim strTableName As String
    Dim cell As Range

    ' Adjust ranges to suit
    Set rngValues = [C2:C8]

    For Each cell In rngValues
        If cell.Value > 95 Then
            MsgBox Range(cell.Address).Offset(0, -1).Value _
                & " table has current size: " & cell.Value
        End If
    Next
End Sub
Sign up to request clarification or add additional context in comments.

2 Comments

This worked absolutely fine. Thanks Jamie. Effort Appreciated.
Hey Jamie...Need more help from you.
0

Try this

Updated to find all instances > threshold

Sub TestRange()
    Dim rngValues As Range
    Dim rngTables As Range
    Dim mxVal As Variant
    Dim idx As Long

    ' Adjust ranges to suit
    Set rngValues = [F1:F10]
    Set rngTables = [E1:E10]
    mxVal = Application.WorksheetFunction.Max(rngValues)
    Do While mxVal > 95
        idx = Application.Match(mxVal, rngValues, 0)
        MsgBox Application.Index(rngTables, idx) & " table has current size: " & mxVal

        If idx < rngValues.Rows.count Then
            Set rngValues = rngValues.Offset(idx, 0).Resize(rngValues.Rows.count - idx)
            Set rngTables = rngTables.Offset(idx, 0).Resize(rngTables.Rows.count - idx)
            mxVal = Application.WorksheetFunction.Max(rngValues)
        Else
            mxVal = 0
        End If
    Loop
End Sub

7 Comments

Chris, again a nice code but it does not fulfill my requirement. What it is doing is: it finds the maximum value in the entire column and if it is above 95 it shows me the msgbox once. But i want that code should display the msgbox equal times as much there are values above 95. For e.g there are 3 values in the entire column above 95, it should display the msgbox three times.
@Jamie Bull - if you have a different solution, post your own answer. Don't vandalise mine
@chris neilsen My apologies. I thought that was the point of a wiki. Added my own.
@Jamie Bull That ok, we live and learn. Editing an answer to improve it is fine. IMHO changing it to a completely different answer is not.
Sorry but it gave me the same output as before..i.e msgbox displayed only once.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.