Formatting as TEXT as opposed to scientific notation

R

Rabbit Farmer

In older version of XL, I had a solution that worked; essentially a
way to automate F2 and Enter via VBA. I now have XL 2000 and it
doesn't seem to work.

Here is what I am doing (before we get into the code to save us all
some time): I have a large CSV file that I open with XL. It opens
directly in XL as opposed to opening the conversion box as it would
with a delimited text file. Some of the columns should be text even
when the entire contents are numbers; they are displayed as 9.91001E
+14 instead of 991001000000000. If I copy this into Access the E+14
format is retained (not very useful). The column contains both text
and number (serial numbers) and the Access database has this column
formatted as Text (for when I paste it into Access).

Anyway, the long way to fix this is to select the column and format it
as text, and then select the first cell, press F2 and then Enter
(repeat a hundred times) to correct the formatting.

There must be an easier way.

Here is my current attempt (since the old method below stopped
working), but it doesn't work (seems to be an issue with the
sendkeys):

Dim Currentcell As Object, Nextcell As Object
Set Currentcell = ActiveSheet.Range("Q1")
Do While Not IsEmpty(Currentcell)
Set Nextcell = Currentcell.Offset(1, 0)
Currentcell.Select
Selection.NumberFormat = "@"
ActiveCell.FormulaR1C1 = Currentcell.Value
Selection.NumberFormat = "@"
SendKeys "{F2}", Wait
SendKeys "{enter}", Wait
Set Currentcell = Nextcell
Loop

The old method was to have this section:
Selection.NumberFormat = "@"
ActiveCell.FormulaR1C1 = Currentcell.Value
Selection.NumberFormat = "@"
SendKeys "{F2}", Wait
SendKeys "{enter}", Wait

Read as:
Selection.NumberFormat = "@"
Currentcell = Currentcell.Value
Selection.NumberFormat = "@"

This used to work. Essentially is said the current cell is equal to
the current cell value.

The number of rows always changes for my data and there are multiple
columns that I will need to run this on. Also, there are sometimes
blanks (the above code works when I do not have blanks, so I did
forced it to work by entering in data just to try to get the rest of
the code to work).

I did a lot of searching on this issue and did see that the sendkeys
method is not recommended, but I couldn't figure out another way.

Thanks in advance.
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top