VBA - Using IsEmpty to check a range of cells

rickyyy2006

New Member
Joined
Nov 21, 2016
Messages
8
Code:
Sub ShowStockWithRisingPotential()

    Dim sheet As Worksheet
    
    Dim CurrentRowNumber As String
    
    Dim RisingValue As Double, RisingThershold As Double, RisingTrend As Double, Result As Variant, i As Integer, j As Integer, Stock As Long
   
    CurrentRowNumber = Application.InputBox("Row Number:")
    
    For Each sheet In Worksheets
        
        With sheet
            
            j = 0
            
            For i = 0 To 30 Step 7
                
                RisingValue = .Cells(Rows.Count, i + 2).End(xlUp).Value
                RisingThershold = .Cells(Rows.Count, i + 3).End(xlUp).Value
                RisingTrend = .Cells(Rows.Count, i + 4).End(xlUp).Value
                
                ResultRTSRV = RisingThershold - RisingValue
                ResultRTRV = RisingTrend - RisingVaule
                ResultRTRTS = RisingTrend - RisingThershold
                Stock = .Cells(1, i + 2).Value


                
[COLOR=#ff0000][B]                If IsEmpty(Range(.Cells(4, i + 4), .Cells(100, i + 4))) = True Then[/B][/COLOR]
[COLOR=#ff0000][B]                    'When Rising Trend is empty[/B][/COLOR]
[COLOR=#ff0000][B]                    If (ResultRTSRV > 0 And ResultRTSRV < 0.1 And IsEmpty(.Cells(CurrentRowNumber, i + 4)) = True And IsEmpty(.Cells(CurrentRowNumber, i + 5)) = True And IsEmpty(.Cells(CurrentRowNumber, i + 6)) = True And IsEmpty(.Cells(CurrentRowNumber, i + 7)) = True) Then[/B][/COLOR]
[COLOR=#ff0000][B]                        MsgBox (sheet.Name & ":" & Stock)[/B][/COLOR]
[COLOR=#ff0000][B]                    Else[/B][/COLOR]
[COLOR=#ff0000][B]                        MsgBox ("Use Next Method")[/B][/COLOR]
[COLOR=#ff0000][B]                    End If[/B][/COLOR]
[COLOR=#ee82ee]                ElseIf IsEmpty(Range(.Cells(4, i + 4), .Cells(100, i + 4))) = False Then[/COLOR]
[COLOR=#ee82ee]                    'When Rising Trend is not empty[/COLOR]
[COLOR=#ee82ee]                   If (ResultRTRTS > 0 And ResultRTRTS < 0.1 And IsEmpty(.Cells(CurrentRowNumber, i + 2)) = True And IsEmpty(.Cells(CurrentRowNumber, i + 5)) = True And IsEmpty(.Cells(CurrentRowNumber, i + 6)) = True And IsEmpty(.Cells(CurrentRowNumber, i + 7)) = True) Then[/COLOR]
[COLOR=#ee82ee]                            MsgBox (sheet.Name & ":" & Stock)[/COLOR]
[COLOR=#ee82ee]                           [/COLOR]
[COLOR=#ee82ee]                    ElseIf (ResultRTRV > 0 And ResultRTRV < 0.1 And IsEmpty(.Cells(CurrentRowNumber, i + 3)) = True And IsEmpty(.Cells(CurrentRowNumber, i + 5)) = True And IsEmpty(.Cells(CurrentRowNumber, i + 6)) = True And IsEmpty(.Cells(CurrentRowNumber, i + 7)) = True) Then[/COLOR]
[COLOR=#ee82ee]                            MsgBox (sheet.Name & ":" & Stock)[/COLOR]
                    End If
            
                End If
            
            Next i
        
        End With
        
    Next sheet
    
End Sub

Dear All

After i completed this code, i found that the red part is wrong so it always comes up with False and run the purple part only.

How can i fix red part?

The red part wants to check if cells from cell (4,4) to cell(100,4) in the first sheet are empty or not. If yes, then go to the underlying if statement.
Then, it checks cells from cell(4,11) to cells(100,11) in the first sheet are empty or not. If yes, then go to the underlying if statement.
The above action loops till the end of the workbook

Thanks
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
You would be better to use worksheet function "CountA" , to check multiple cells. If it returns 0 the range is empty !!!
 
Upvote 0

Forum statistics

Threads
1,216,114
Messages
6,128,913
Members
449,478
Latest member
Davenil

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