Loop through multiple data validation lists

Waimea

Active Member
Joined
Jun 30, 2018
Messages
465
Office Version
  1. 365
Platform
  1. Windows
In this thread https://www.ozgrid.com/forum/forum/...p-down-list-and-copy-paste-the-value?t=190022 I found the following code. I have cross-posted this at https://www.ozgrid.com/forum/forum/...ooping-through-multiple-data-validation-lists

Code:
Option Explicit


Sub CostModelOutput()
    Dim dvCell As Range, dvCell2 As Range
    Dim inputRange As Range, inputRange2 As Range
    Dim c As Range, d As Range
    Dim i As Long, j As Long
    Dim NumberRows As Long, NumberRows2 As Long
    
    
     'Which cell has data validation
    Set dvCell = Worksheets("Input").Range("J28")
    Set dvCell2 = Worksheets("Input").Range("N28")
     'Determine where validation comes from
    Set inputRange = Evaluate(Range("J28").Validation.Formula1)
    Set inputRange2 = Evaluate(Range("N28").Validation.Formula1)
    
    i = 3
    'Begin our loop
    Application.ScreenUpdating = True
        Sheets("Input").Activate
    
    For Each c In inputRange
        dvCell = c.Value
        MsgBox dvCell
        
        NumberRows = Application.WorksheetFunction.CountA(Columns("A:U"))
        Range("X2").Value = NumberRows
        Worksheets("Output").Cells(i, "B").Value = Worksheets("Input").Range("C4").Value
        
        Debug.Print dvCell
        
        
        i = i + 1
    Next c
    
     Sheets("Input").Activate
        j = 3
    For Each d In inputRange2
        
        
        
        dvCell2 = d.Value
        MsgBox dvCell2
        NumberRows2 = Application.WorksheetFunction.CountA(Columns("A:U"))
        Range("y2").Value = NumberRows2
        Worksheets("Output").Cells(i, "B").Value = Worksheets("Input").Range("C4").Value
        
        
        'Worksheets("Output").Cells(i, "B").Value = Worksheets("Input").Range("C4").Value
        'Worksheets("Output").Cells(i, "C").Value = Worksheets("Input").Range("C5").Value
        'Worksheets("Output").Cells(i, "E").Value = Worksheets("Input").Range("C1").Value
        'Worksheets("Output").Cells(i, "F").Value = Worksheets("Input").Range("H1").Value
        
         j = j + 1
    Next d
       
    Application.ScreenUpdating = True
     
End Sub

How can I incorporate the second for each loop in the first loop? I want the for each loops to step every step in the data validation cells and count the number of X and Y.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,215,770
Messages
6,126,794
Members
449,337
Latest member
BBV123

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