Counting items in a loop

ShawnTMc

New Member
Joined
Mar 18, 2019
Messages
6
Excel newbie here,

This is most likely going to be an easy one to answer.

I'm just trying to figure out how to count the number of items the following loop successfuly goes through. I'm looking to create a message box at the end of this loop to show how many items were saved. Something like " (item count number) Excel Documents Extracted."

This is what I have so far.

----------------------------------------------------

1597338835362.png
 

Attachments

  • 1597338447016.png
    1597338447016.png
    28.4 KB · Views: 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Dim a variable as Long for counting, say N for this example. It will default to a value of 0. So, inside your inner For..Next loop, put this line of code...

N = N + 1

That way, ever loop, the N variable will increase in value by 1. So, at the end of the code, before it ends, put a MessageBox statement that displays N.
 
Upvote 0
Dim a variable as Long for counting, say N for this example. It will default to a value of 0. So, inside your inner For..Next loop, put this line of code...

N = N + 1

That way, ever loop, the N variable will increase in value by 1. So, at the end of the code, before it ends, put a MessageBox statement that displays N.

Thank you Rick. That's exactly what I was looking. I was trying to figure it out logically but I couldn't grasp how the loop would know to store the count value in "N".
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,892
Members
449,194
Latest member
JayEggleton

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