![]() |
Do Loop
I'd like to loop through column 3 of my datafile to find all empty cells in this field. Because I'd like to loop down through each row I've created an iLastRow variable so that the loop can Do Until it reaches iLastRow. The bit I'd like some help with is.. The empty cells can be identified in two ways, either that they are empty, so you could say do until is empty or that they have a colourindex of 15, whichever is more efficient. Then.... Where VBA finds a cell matching this criteria, I need to grab the contents from the cell above to populate the 'found' cell. Does this make sense? That way all my fields in column 3 will be populated with a value so I can run an autofilter against it. Can anyone kindly help with the syntax? Many thanks Jacqui |
Do Loop
Jacqui,
Sub test() Dim i As Long, lngLastRow As Long With Sheet1 lngLastRow = .Cells(Rows.Count, 3).End(xlUp).Row For i = 2 To lngLastRow 'assuming cell 1 is always populated If .Cells(i, 3).Value = "" Then .Cells(i, 3).Value = .Cells(i - 1, 3).Value Next End With End Sub Rob "jacqui" wrote in message ... I'd like to loop through column 3 of my datafile to find all empty cells in this field. Because I'd like to loop down through each row I've created an iLastRow variable so that the loop can Do Until it reaches iLastRow. The bit I'd like some help with is.. The empty cells can be identified in two ways, either that they are empty, so you could say do until is empty or that they have a colourindex of 15, whichever is more efficient. Then.... Where VBA finds a cell matching this criteria, I need to grab the contents from the cell above to populate the 'found' cell. Does this make sense? That way all my fields in column 3 will be populated with a value so I can run an autofilter against it. Can anyone kindly help with the syntax? Many thanks Jacqui |
All times are GMT +1. The time now is 10:25 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com