In , Dave Peterson
spake thusly:
You'll want to change this line:
iLastCol = Cells.SpecialCells(xlCellTypeLastCell).Column
to
iLastCol = .Cells.SpecialCells(xlCellTypeLastCell).Column
This extra dot means that excel will use the correct worksheet
(With Worksheets("2006 Realized Gains"))
Another way is if you can pick out a row that always has data:
With Worksheets("2006 Realized Gains")
iLastCol = .cells(1,.columns.count).end(xltoleft).column
...
I used row 1 to determine the last used column.
Thanks again, Dave!
Sometimes excel's lastusedcell won't be what you expect it to be.
I've occasionally found that out; yup! :-) (But so far, not with
this macro.)
Or visit Debra Dalgleish's site for some techniques for resetting that
lastusedcell.
http://www.contextures.com/xlfaqApp.html#Unused
Will do.
Dallman