ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Importing from SQL as a Number instead of Text (https://www.excelbanter.com/excel-programming/417783-importing-sql-number-instead-text.html)

Jez

Importing from SQL as a Number instead of Text
 
I have code that imports a query from SQL Server and pastes the results into
certain cells. This works great, my problem is that when I come to find the
Max number from a range of cells, they all seem to be as Text...

How can when importing them change them from Text to Number?

joel

Importing from SQL as a Number instead of Text
 
I can't tell what the problem is without seeing the SQL statements. The data
may be stored in the database (or website) in text format, th eSQL statements
may be converting the numbers to text, or the spreadsheet may be formated as
text.

Here are some thngs to check

1) Click on a cell and see if there is a single quote infront of the number
or a space in front of the number.
2) click on the cell and then check the format by going to menu Format -
Cels - Number ans seeing which format is highlighted. If the format is TEXT
change format to number or general.

"Jez" wrote:

I have code that imports a query from SQL Server and pastes the results into
certain cells. This works great, my problem is that when I come to find the
Max number from a range of cells, they all seem to be as Text...

How can when importing them change them from Text to Number?


Jez

Importing from SQL as a Number instead of Text
 
All the Cells are already set to General, The Field I take them from in SQL
Server is an INT.
Clicking on the cell shows no single quote or space in front of the number

I dont know where to go from here

"Joel" wrote:

I can't tell what the problem is without seeing the SQL statements. The data
may be stored in the database (or website) in text format, th eSQL statements
may be converting the numbers to text, or the spreadsheet may be formated as
text.

Here are some thngs to check

1) Click on a cell and see if there is a single quote infront of the number
or a space in front of the number.
2) click on the cell and then check the format by going to menu Format -
Cels - Number ans seeing which format is highlighted. If the format is TEXT
change format to number or general.

"Jez" wrote:

I have code that imports a query from SQL Server and pastes the results into
certain cells. This works great, my problem is that when I come to find the
Max number from a range of cells, they all seem to be as Text...

How can when importing them change them from Text to Number?


joel

Importing from SQL as a Number instead of Text
 
A easy way to really determine if a cell is Text or a number is to use the
formula
=Sum(A1)

If the formula returns zero then the cell A1 is Text, otherwise it will
return the number in A1. You can change th eformula to any cell or range of
cells like
=Sum(A1:A5) or you can use =Max(A1:A5)

One possibility is there is a problem with only some of the cells and not
all the cells. Experiment a try to isolate the problem by changing the range
of the cells in the formula(s) until you find which ones are problems.



"Jez" wrote:

All the Cells are already set to General, The Field I take them from in SQL
Server is an INT.
Clicking on the cell shows no single quote or space in front of the number

I dont know where to go from here

"Joel" wrote:

I can't tell what the problem is without seeing the SQL statements. The data
may be stored in the database (or website) in text format, th eSQL statements
may be converting the numbers to text, or the spreadsheet may be formated as
text.

Here are some thngs to check

1) Click on a cell and see if there is a single quote infront of the number
or a space in front of the number.
2) click on the cell and then check the format by going to menu Format -
Cels - Number ans seeing which format is highlighted. If the format is TEXT
change format to number or general.

"Jez" wrote:

I have code that imports a query from SQL Server and pastes the results into
certain cells. This works great, my problem is that when I come to find the
Max number from a range of cells, they all seem to be as Text...

How can when importing them change them from Text to Number?


joel

Importing from SQL as a Number instead of Text
 
You can use this simple macro to find the cells that are text. Cahnge the
range A1:D10 as required.


Sub findtext()

Set SearchRange = Range("A1:D10")

For Each cell In SearchRange
If Not IsNumeric(cell) Then
MsgBox ("Cell : " & cell.Address & " is Text")
End If
Next cell
End Sub

"Jez" wrote:

All the Cells are already set to General, The Field I take them from in SQL
Server is an INT.
Clicking on the cell shows no single quote or space in front of the number

I dont know where to go from here

"Joel" wrote:

I can't tell what the problem is without seeing the SQL statements. The data
may be stored in the database (or website) in text format, th eSQL statements
may be converting the numbers to text, or the spreadsheet may be formated as
text.

Here are some thngs to check

1) Click on a cell and see if there is a single quote infront of the number
or a space in front of the number.
2) click on the cell and then check the format by going to menu Format -
Cels - Number ans seeing which format is highlighted. If the format is TEXT
change format to number or general.

"Jez" wrote:

I have code that imports a query from SQL Server and pastes the results into
certain cells. This works great, my problem is that when I come to find the
Max number from a range of cells, they all seem to be as Text...

How can when importing them change them from Text to Number?


Jez

Importing from SQL as a Number instead of Text
 
Thanks I tried that code over the whole range of data and spent time looking
at each cell. All cells I was looking to be as a number were and all the text
fields were text fields, so I dont understand why this doesnt work...

=MAX(C12,F12,I12,C24,F24)

"Joel" wrote:

You can use this simple macro to find the cells that are text. Cahnge the
range A1:D10 as required.


Sub findtext()

Set SearchRange = Range("A1:D10")

For Each cell In SearchRange
If Not IsNumeric(cell) Then
MsgBox ("Cell : " & cell.Address & " is Text")
End If
Next cell
End Sub

"Jez" wrote:

All the Cells are already set to General, The Field I take them from in SQL
Server is an INT.
Clicking on the cell shows no single quote or space in front of the number

I dont know where to go from here

"Joel" wrote:

I can't tell what the problem is without seeing the SQL statements. The data
may be stored in the database (or website) in text format, th eSQL statements
may be converting the numbers to text, or the spreadsheet may be formated as
text.

Here are some thngs to check

1) Click on a cell and see if there is a single quote infront of the number
or a space in front of the number.
2) click on the cell and then check the format by going to menu Format -
Cels - Number ans seeing which format is highlighted. If the format is TEXT
change format to number or general.

"Jez" wrote:

I have code that imports a query from SQL Server and pastes the results into
certain cells. This works great, my problem is that when I come to find the
Max number from a range of cells, they all seem to be as Text...

How can when importing them change them from Text to Number?



All times are GMT +1. The time now is 01:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com