I'm trying to write a macro (Excel 2007) that will iterate through one column at a time, searching for a value of "n", and output the value from column A to another sheet. I have managed to make it work for one column, but trying to get it to increment through the other columns is proving more difficult than expected.
Here is the code I used to pull the information from one column
I tried to wrap the loop in another loop to increment the column after reaching the bottom of the column;
Dim i
Dim e
Set i = Sheets("HVAC (PM)")
Set e = Sheets("HVAC (PM) Schedule")
Dim outRow
Dim inRow
Dim outCol As String
Dim inCol As String
outRow = 1
inRow = 7
outCol = "A"
inCol = "B"
Do Until IsEmpty(i.Range(inCol & inRow))
inRow = 7
Do Until IsEmpty(i.Range(inCol & inRow))
If i.Range(inCol & inRow) = "n" Then
outRow = outRow + 1
e.Cells(outCol, outRow).Value = i.Cells(inCol, inRow).Value
inRow = inRow + 1
End If
Loop
inCol = inCol + 1
outCol = outCol + 1
Loop
End Sub
This gets stuck in an endless loop. I can't seem to figure out what is going wrong. Any help would be very much appreciated.
It is entirely likely I've fubar'd the syntax or even gone about this the wrong way, if you know of a better solution or if you could help me make my solution work, I would be eternally in your debt.
Here is the code I used to pull the information from one column
Set i = Sheets("ACHR (pm)")
Set e = Sheets("ACHR (PM) Schedule")
Dim outRow
Dim inRow
outRow = 1
inRow = 7
Do Until IsEmpty(i.Range("B" & j))
If i.Range("B" & j) = "n" Then
d = d + 1
e.Rows(d).Value = i.Rows(j).Value
End If
j = j + 1
Loop
It works fine, but pulls the whole row (I only need the value from column A) and only searches column B.Set e = Sheets("ACHR (PM) Schedule")
Dim outRow
Dim inRow
outRow = 1
inRow = 7
Do Until IsEmpty(i.Range("B" & j))
If i.Range("B" & j) = "n" Then
d = d + 1
e.Rows(d).Value = i.Rows(j).Value
End If
j = j + 1
Loop
I tried to wrap the loop in another loop to increment the column after reaching the bottom of the column;
Dim i
Dim e
Set i = Sheets("HVAC (PM)")
Set e = Sheets("HVAC (PM) Schedule")
Dim outRow
Dim inRow
Dim outCol As String
Dim inCol As String
outRow = 1
inRow = 7
outCol = "A"
inCol = "B"
Do Until IsEmpty(i.Range(inCol & inRow))
inRow = 7
Do Until IsEmpty(i.Range(inCol & inRow))
If i.Range(inCol & inRow) = "n" Then
outRow = outRow + 1
e.Cells(outCol, outRow).Value = i.Cells(inCol, inRow).Value
inRow = inRow + 1
End If
Loop
inCol = inCol + 1
outCol = outCol + 1
Loop
End Sub
It is entirely likely I've fubar'd the syntax or even gone about this the wrong way, if you know of a better solution or if you could help me make my solution work, I would be eternally in your debt.