There are three columns. one has some names of tables and second column has its free space and third has percentage used.
help required is:
- Msgbox should display the value of PERCENTAGE USED column in the cell it finds more than 90.
- Also it should display the name of the corresponding table and the free space of the table for which it is displaying the value in step one.
msgbox output should be:
“ABCD table is 96.67% used and space left is: 7431MB ”
Sample Code which displays only table name and percentage used:
Dim rngValues As Range
Dim strTableName As String
Dim cell As Range
' Adjust ranges to suit
Set rngValues = [JI3:JI90]
For Each cell In rngValues
If cell.Value > 94.45 Then
cell.Select
MsgBox Range(cell.Address).Offset(0, -268).Value _
& " table has current size: " & cell.Value
cell.Interior.Color = RGB(255, 0, 0)
End If
Sample output of this code : ABCD table has current size : 97.87%
One way to solve this problem is to use a second
Range(cell.Address).Offset().Valuestatement to append the additional information to the text being displayed by the message box. The exact code is going to depend on how many columns away from column ‘JI’ the column showing the free space left is.Assuming that it is the column before the one containing the % space used you could do the following:
If it isn’t the column before the one containing the % space used you simply need to adjust the column offset in
Range(cell.Address).Offset(0,-1).Valueproperly. For example if the column containing free space occurrs 9 columns after column JI change the Offset toOffset(0,9)The first argument between the parentheses for Offset is the number of rows and the second one is the number of columns. negative offsets specify rows or columns appearing before the selected cell, postivive specify rows or columns appearing after the selected cell. ‘0’ specifies the current row or column.