Create an Array and transpose array values to range

Drawleeh

New Member
Joined
Sep 2, 2021
Messages
34
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Hello, I have some code that will loop through each worksheet in my workbook and then fetch the amount of rows and populate integer 'rowcount' with that number. How do I then take that integer, store all of those values in an array and then transpose that array onto a range so it looks something like this?

1638533488159.png


Where all the values are the number of rows on the worksheet and the worksheet name is titled above that value (as shown above). The worksheets are all in the same order as above.

VBA Code:
Sub Totals()

Dim wrksheet As Worksheet
Dim x As Long
Dim rowcount As Integer


For Each wrksheet In ActiveWorkbook.Worksheets
    If wrksheet.Visible And Not wrksheet.Name = "Log" Then

        With wrksheet
       
                rowcount = .Range("B2", .Range("B" & .Rows.Count).End(xlUp)).Rows.Count
           
            End With

        End If
Next wrksheet
  

End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try
VBA Code:
Sub Totals()

Dim wrksheet As Worksheet
Dim x As Long
Dim rowcount As Integer
Dim Ary As Variant

ReDim Ary(1 To 2, 1 To ActiveWorkbook.Worksheets.Count)

For Each wrksheet In ActiveWorkbook.Worksheets
    If wrksheet.Visible And Not wrksheet.Name = "Log" Then

        With wrksheet
                x = x + 1
                Ary(1, x) = .b = Name
                Ary(2, x) = .Range("B2", .Range("B" & .Rows.Count).End(xlUp)).Rows.Count
           
            End With

        End If
Next wrksheet
Sheets("Sheet2").Range("A1").Resize(2, x).Value = Ary

End Sub
 
Upvote 0
Solution
Try
VBA Code:
Sub Totals()

Dim wrksheet As Worksheet
Dim x As Long
Dim rowcount As Integer
Dim Ary As Variant

ReDim Ary(1 To 2, 1 To ActiveWorkbook.Worksheets.Count)

For Each wrksheet In ActiveWorkbook.Worksheets
    If wrksheet.Visible And Not wrksheet.Name = "Log" Then

        With wrksheet
                x = x + 1
                Ary(1, x) = .b = Name
                Ary(2, x) = .Range("B2", .Range("B" & .Rows.Count).End(xlUp)).Rows.Count
          
            End With

        End If
Next wrksheet
Sheets("Sheet2").Range("A1").Resize(2, x).Value = Ary

End Sub

I get method or data member not found error at .b? I'm not sure I understand what you're referencing with .b either to fix it.
 
Upvote 0
Not sure what happened there, but that should read
VBA Code:
Ary(1, x) = .Name
 
Upvote 0

Forum statistics

Threads
1,223,934
Messages
6,175,488
Members
452,648
Latest member
Candace H

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