G
Greg Lovern
If I run Range.Formula = Range.Formula on a given range of blank cells
formatted as text, the following problems occur:
-- Range.End treats those cells as occupied, not as blank.
-- Worksheetfunction.CountA treats those cells as occupied, not as blank.
-- Saving out as a tab-delimited text file saves out a tab character between
each affected cell, as though the cells were occupied.
In our project, users paste long text strings that look like numbers to
Excel. Even if I protect the formatting, Excel allows pasting in formatting,
including number formatting. And these users often copy from other rich-text
sources such as Outlook, then paste into Excel, so what looked like
123456789012 in Outlook looks like 1.234567E+11 when they paste it in. I've
discussed paste special | values, and copying to Notepad,and I even provided
an import feature. But of course they're still pasting from Outlook. Oh, and
there are tens of thousands of users, and growing.
I've been asked to make it automatically convert back to text format, so on
the worksheet's Change event I'm changing the target range's number
formatting back to "@" (which is how we send the workbook out to users), and
since that alone isn't enough, I then do a range.Formula = range.Formula on
the target range, equivalent to pressing F2 and then Enter. Yes, I realize
any leading zeros are lost forever, along with any digits after the 15th, and
I've covered that with them, but this is what they want.
Steps to reproduce the problem:
-- In a new sheet, select row 1 (the whole row).
-- Set the number formatting of that row to Text (right-click anywhere in
the selected row | Number tab | Text).
-- enter any data in cells A1:C1.
-- In the VBA Immediate pane, paste in this command and press enter:
activesheet.range("A1").end(xltoright).select
-- it should select cell C1. So far so good.
-- In the VBA Immediate pane, paste in this command and press enter:
activesheet.rows(1).formula = activesheet.rows(1).formula
-- Then run the first command again:
activesheet.range("A1").end(xltoright).select
-- This time, it does NOT select cell C1. Instead, it selects cell XFD1 if
you are in Excel 2007, or cell IV1 if you are in Excel 2003 or earlier. This
is the same result you would get if you had entered data in ALL cells in row
1.
Why does this happen?
Thanks,
Greg Lovern
http://PrecisionCalc.com
More Power In Excel
formatted as text, the following problems occur:
-- Range.End treats those cells as occupied, not as blank.
-- Worksheetfunction.CountA treats those cells as occupied, not as blank.
-- Saving out as a tab-delimited text file saves out a tab character between
each affected cell, as though the cells were occupied.
In our project, users paste long text strings that look like numbers to
Excel. Even if I protect the formatting, Excel allows pasting in formatting,
including number formatting. And these users often copy from other rich-text
sources such as Outlook, then paste into Excel, so what looked like
123456789012 in Outlook looks like 1.234567E+11 when they paste it in. I've
discussed paste special | values, and copying to Notepad,and I even provided
an import feature. But of course they're still pasting from Outlook. Oh, and
there are tens of thousands of users, and growing.
I've been asked to make it automatically convert back to text format, so on
the worksheet's Change event I'm changing the target range's number
formatting back to "@" (which is how we send the workbook out to users), and
since that alone isn't enough, I then do a range.Formula = range.Formula on
the target range, equivalent to pressing F2 and then Enter. Yes, I realize
any leading zeros are lost forever, along with any digits after the 15th, and
I've covered that with them, but this is what they want.
Steps to reproduce the problem:
-- In a new sheet, select row 1 (the whole row).
-- Set the number formatting of that row to Text (right-click anywhere in
the selected row | Number tab | Text).
-- enter any data in cells A1:C1.
-- In the VBA Immediate pane, paste in this command and press enter:
activesheet.range("A1").end(xltoright).select
-- it should select cell C1. So far so good.
-- In the VBA Immediate pane, paste in this command and press enter:
activesheet.rows(1).formula = activesheet.rows(1).formula
-- Then run the first command again:
activesheet.range("A1").end(xltoright).select
-- This time, it does NOT select cell C1. Instead, it selects cell XFD1 if
you are in Excel 2007, or cell IV1 if you are in Excel 2003 or earlier. This
is the same result you would get if you had entered data in ALL cells in row
1.
Why does this happen?
Thanks,
Greg Lovern
http://PrecisionCalc.com
More Power In Excel