alphiealphie
New Member
- Joined
- Jul 15, 2013
- Messages
- 3
I am attempting to use Excel to fill in the blank cells in an organisational hierarchy I have. Before and After scenarios below.
I have attempted pseudocode on this.
For all rows
For all cells in row
If cell is populated, row++
If cell is not populated, copy the value immediately above to the current cell and check next cell in row
Here are my ideal before/after shots
So far i have this but it's not achiving the right result - cell C10 should not populate in my example. I would love some help!
Sub FillTree()
Dim rng as Range
Dim r as Range
Dim c as Range
Dim cl as Range
Set rng = Range("A1:E50") '## Modify this to the full range you want to fill in.
For Each c In rng.Columns '# iterate over each column
For Each cl in c.Cells '# check each cell in the column
If Trim(cl) = vbNullString Then '# if the cell is empty, fill from above
cl = cl.Offset(-1,0)
Else: '# do nothing if the cell is not empty
End If
Next
Next
End Sub
I have attempted pseudocode on this.
For all rows
For all cells in row
If cell is populated, row++
If cell is not populated, copy the value immediately above to the current cell and check next cell in row
Here are my ideal before/after shots
So far i have this but it's not achiving the right result - cell C10 should not populate in my example. I would love some help!
Sub FillTree()
Dim rng as Range
Dim r as Range
Dim c as Range
Dim cl as Range
Set rng = Range("A1:E50") '## Modify this to the full range you want to fill in.
For Each c In rng.Columns '# iterate over each column
For Each cl in c.Cells '# check each cell in the column
If Trim(cl) = vbNullString Then '# if the cell is empty, fill from above
cl = cl.Offset(-1,0)
Else: '# do nothing if the cell is not empty
End If
Next
Next
End Sub