In Excel VBA:
My second For-Each loop is only going through the first cell in a given column. I need help getting it to go through each cell in the entire column.
In my code included here, I want to loop through each cell in a row (no issue). then once a cell in the row matches my criteria (no issue), I want to loop through each cell (celltwo) in that cell's column (issue).
I'm able to loop through the row and identify my criteria, but then the second for-each loop only considers the first celltwo in the given column. So I never get a celltwo with .row >=10, the first cell in each column has row=1.
Any help is appreciated.
This is for VBA in Excel. I've tried different ways of identifying my second range to loop through but nothing has allowed the second for-each loop to cycle back from "Next Celltwo" to the beginning of the loop.
Sub WriteSummary()
Dim UploadRange As Range
Dim SummaryRow As Integer
Dim CategoryRange As Range
Dim Cell As Range
Dim Celltwo As Range
''''''''''''''''''''''''''''''''''''''''''''''''''''
'Set Variables
Set MacroFile = ThisWorkbook
Set MacroSheet = ThisWorkbook.Worksheets("Macro")
Set UploadDash = ThisWorkbook.Worksheets("Upload Dash")
Set SummarySheet = ThisWorkbook.Worksheets("Summary")
Set IndexSheet = ThisWorkbook.Worksheets("Indexes")
Set CategoryRange = UploadDash.Range("5:5")
''''''''''''''''''''''''''''''''''''''''''''''''''''
'Determine Output Row
SummaryRow = SummarySheet.Cells(Rows.Count, 1).End(xlUp).Row + 1
''''''MY PROBLEM STARTS HERE'''''''
For Each Cell In CategoryRange
If Cell.Value = 8840 Then
For Each Celltwo In SummarySheet.Cells(, Cell.Column).EntireColumn
i = MsgBox(Celltwo.Row, vbOKOnly)
If Celltwo.Row >= 10 Then
If Celltwo.Value > 0 Then
o = MsgBox(Celltwo.AddressLocal)
SummaryRow = SummaryRow + 1
Else
End If
Else
End If
Next Celltwo '''''DOES NOT LOOP'''''
Else
End If
Next Cell
I expect that when the code finds cell.value = 8840 it will then loop through each cell in that cell's column. Instead, it only loops through the first cell in that column and exits the second for-each loop
Aucun commentaire:
Enregistrer un commentaire