John Steel
New Member
- Joined
- Feb 7, 2017
- Messages
- 12
Good day everyone,
I have a simple code I'm using to trim leading/trailing spaces from two ranges and I would like to exit the loop when it encounters a blank entry in those ranges. Most often only 1-3 rows of the range are populated with data and I don't need the loop running unnecessarily through blank cells.
My code is as follows.
Dim cell As Range, areaToTrim As Range 'This trims off leading and trailing spaces in the address and zoning columns from the MLS data dump on the File Information Sheet
Set areaToTrim = Sheet1.Range("B28:B57", "Bk28:BK57")
For Each cell In areaToTrim
cell.Value = Trim(cell.Value)
Next cell
I've tried inserting the following after line 3 but it doesn't accomplish what I want
If cell.Value = "" Then Exit For
Any suggestions would be appreciated.
Thanks
I have a simple code I'm using to trim leading/trailing spaces from two ranges and I would like to exit the loop when it encounters a blank entry in those ranges. Most often only 1-3 rows of the range are populated with data and I don't need the loop running unnecessarily through blank cells.
My code is as follows.
Dim cell As Range, areaToTrim As Range 'This trims off leading and trailing spaces in the address and zoning columns from the MLS data dump on the File Information Sheet
Set areaToTrim = Sheet1.Range("B28:B57", "Bk28:BK57")
For Each cell In areaToTrim
cell.Value = Trim(cell.Value)
Next cell
I've tried inserting the following after line 3 but it doesn't accomplish what I want
If cell.Value = "" Then Exit For
Any suggestions would be appreciated.
Thanks