VBA - Check if data has a specific number of rows

TheHack22

Board Regular
Joined
Feb 3, 2021
Messages
121
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi VBA Experts,

I've looked around but couldn't find a VBA Sub to do my task.
I have a Sub that takes a dataset, creates a Pivot Table of it, then copies and pastes it to another place.
The issue is that sometimes that dataset doesn't have all the data, because of glitches.
Is there a Sub that I can use to check the Summarized data to ensure that the data is the last 7 days(7 rows + Column Label)?
If the summarized data doesn't = 7 rows, I would like to see a Msg indicating the same.

Imran
 

Attachments

  • Image.16438071313600.png
    Image.16438071313600.png
    15.4 KB · Views: 9

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try:
VBA Code:
Sub CountRows()
    If Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row - 1 <> 7 Then
        MsgBox ("The summarized data doesn't have 7 rows.")
    End If
End Sub
 
Upvote 0
Try:
VBA Code:
Sub CountRows()
    If Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row - 1 <> 7 Then
        MsgBox ("The summarized data doesn't have 7 rows.")
    End If
End Sub
@mumps

Thanks very much for your response. I just realized that the image I posted is a little misleading.
This data range is Col AI: Col AM. This is the range I would like the Sub to analyze: = 7 Rows.
Imran
 
Upvote 0
Try:
VBA Code:
Sub CountRows()
    If Range("AI" & Rows.Count).End(xlUp).Row - 1 <> 7 Then
        MsgBox ("The summarized data doesn't have 7 rows.")
    End If
End Sub
 
Upvote 0
Solution
Try:
VBA Code:
Sub CountRows()
    If Range("AI" & Rows.Count).End(xlUp).Row - 1 <> 7 Then
        MsgBox ("The summarized data doesn't have 7 rows.")
    End If
End Sub
@mumps

Thanks a million. This is awesome :)
Imran
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,214,411
Messages
6,119,356
Members
448,888
Latest member
Arle8907

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