Switch formula control system to VBA code

Aretradeser

Board Regular
Joined
Jan 16, 2013
Messages
176
Office Version
  1. 2013
Platform
  1. Windows
On Sheet1 I have a series of data. In column 2, there are name records; and, from column 3 to column 14, titled with the months of the year, with number records.
On Sheet2, in row 4, from column 10 to 21, I have a formula that detects which name has a zero record and records it in the corresponding month column on Sheet2.
Excel Formula:
=IFERROR(INDEX(Sheet1!$B$3:$B$25;AGGREGATE(15;6;(ROW(Sheet1!$B$3:$B$25)-ROW(Sheet1!$B$3)+1)/(Sheet1!C$3:C$25=0);ROWS(J$4:J4)));"")
However, I see a small problem with the manual application of this system.
Currently, I have about 1200 records, which will increase; and, with this formula application system, I have to drag them until I reach the last row of the column in which there are no more records that meet this condition.
My question is the following:
Could it be done with VBA code and execute it with a button, that would do the same; and that, in addition, would register the new names that meet this condition?
Libro1.xlsx
BCDEFGHIJKLMN
2NAMESJANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC
3Name12303571023010
4Name22210614012300910
5Name32456040106240
6Name421411148713060
7Name52273611401414114
8Name6135731400111404
9Name72278101211205138
10Name8233040146000
11Name9240013119910395
12Name10043101001318993
13Name11205068008534
14Name12023131081367100
15Name13019714121006704
16Name141049013050024
17Name151097130012101303
18Name1623891161001000
19Name170901912111471200
20Name18059471043114913
21Name19100547700001
22Name2006121130321135
23Name21621706601008
24Name220678100010037
25Name2328135341070100
Hoja1

Cell Formulas
RangeFormula
J4:U12J4=IFERROR(INDEX(Hoja1!$B$3:$B$25,AGGREGATE(15,6,(ROW(Hoja1!$B$3:$B$25)-ROW(Hoja1!$B$3)+1)/(Hoja1!C$3:C$25=0),ROWS(J$4:J4))),"")
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Are you asking if the whole thing can be done with a macro, or if a macro can insert the formula?
 
Upvote 0
Ok, how about
VBA Code:
Sub Aretradeser()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, nr As Long, Mx As Long
   
   With Sheets("Hoja1")
      Ary = .Range("B3:N" & .Range("B" & Rows.Count).End(xlUp).Row).Value2
   End With
   ReDim Nary(1 To UBound(Ary), 1 To UBound(Ary, 2) - 1)
   
   For c = 2 To UBound(Ary, 2)
      nr = 0
      For r = 1 To UBound(Ary)
         If Ary(r, c) = 0 Then
            nr = nr + 1
            Nary(nr, c - 1) = Ary(r, 1)
            If nr > Mx Then Mx = nr
         End If
      Next r
   Next c
   Sheets("Hoja2").Range("J4").Resize(Mx, UBound(Nary, 2)).Value = Nary
End Sub
 
Upvote 0
Solution
Ok, how about
VBA Code:
Sub Aretradeser()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, nr As Long, Mx As Long
  
   With Sheets("Hoja1")
      Ary = .Range("B3:N" & .Range("B" & Rows.Count).End(xlUp).Row).Value2
   End With
   ReDim Nary(1 To UBound(Ary), 1 To UBound(Ary, 2) - 1)
  
   For c = 2 To UBound(Ary, 2)
      nr = 0
      For r = 1 To UBound(Ary)
         If Ary(r, c) = 0 Then
            nr = nr + 1
            Nary(nr, c - 1) = Ary(r, 1)
            If nr > Mx Then Mx = nr
         End If
      Next r
   Next c
   Sheets("Hoja2").Range("J4").Resize(Mx, UBound(Nary, 2)).Value = Nary
End Sub
Fluff, your macro works perfectly. Thank you very much. It's a luxury to have people like you in this fantastic forum.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,301
Members
449,078
Latest member
nonnakkong

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