Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Excel - What function to convert text to a number?

Thread Tools
 
Search this Thread
 
Old 14 February 2008, 03:17 PM
  #1  
GazTheHat
Scooby Regular
Thread Starter
 
GazTheHat's Avatar
 
Join Date: Aug 2005
Location: 392/361 MY04 STi
Posts: 7,638
Likes: 0
Received 0 Likes on 0 Posts
Default Excel - What function to convert text to a number?

OK, i know very little VBA and i've got to modify this macro.

It's reading in a value from a file, then placing it in the worksheet. It does this fine, but when it is put in the sheet, there is a "!" box next to the number, which when clicked says to convert it to a number.

Now i would like to do this automatically. I've searched for keyphrases, but i've got nothing so far.

Here's a snip of the macro:

Dim InvoiceTotal
.
.
.
' Open the totals file and process it
Open "C:\temp\totals8.dat" For Input As #1
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, InvoiceTotal ' Read line into variable.
Loop
Close #1 ' Close file.
.
.
.
' Overall Total Clients
Worksheets("Sheet1").Range("O" & intRow + 2).Activate
ActiveCell.Formula = InvoiceTotal
ActiveCell.Font.Bold = True
Old 14 February 2008, 03:26 PM
  #2  
ChefDude
Scooby Regular
 
ChefDude's Avatar
 
Join Date: Aug 2005
Posts: 4,290
Likes: 0
Received 0 Likes on 0 Posts
Default

clng()
cdbl()
cint()
Old 14 February 2008, 03:57 PM
  #3  
Dracoro
Scooby Regular
 
Dracoro's Avatar
 
Join Date: Sep 2001
Location: A powerslide near you
Posts: 10,261
Likes: 0
Received 0 Likes on 0 Posts
Default

Alos, as a side note, try to avoid using activate and activecell. It slows down processing, can cause confusion to user (excel screen flashing here there and everywhere) and can be a nightmare to maintain as code grows. Also, if you wanted to use something else (vb, or word etc.) that accesses the excel object library you won't be able to convert the code easily.

use: (although you may need to use cell rather than range, I can't remember which in these cases, but you get the general idea etc....)
Worksheets("Sheet1").Range("O" & intRow + 2).Formula = InvoiceTotal
Worksheets("Sheet1").Range("O" & intRow + 2).Font.Bold = True
Old 14 February 2008, 07:03 PM
  #4  
Swen6
Scooby Regular
 
Swen6's Avatar
 
Join Date: Jun 2005
Posts: 2,721
Likes: 0
Received 0 Likes on 0 Posts
Default

Not sure if this is what your talking about.

RIGHT CLICK on the cells, choose FORMAT CELLS and then check the CATEGORY on the NUMBER TAB, if this is set to the wrong setting when you imput numbers it changes the values.

Sorry if i've got the wrong end....
Old 15 February 2008, 11:33 AM
  #5  
GazTheHat
Scooby Regular
Thread Starter
 
GazTheHat's Avatar
 
Join Date: Aug 2005
Location: 392/361 MY04 STi
Posts: 7,638
Likes: 0
Received 0 Likes on 0 Posts
Default

Originally Posted by ChefDude
clng()
cdbl()
cint()
clng, of course.

No wander i didn't find it when searching for "convert".

Thanks, worked a treat!!


Now off to try Dracoro's suggestion, because the sheet is populated with about 1500 lines and a dozen cells. It flashes the **** outta the screen, i can't believe the users haven't had seizures.

That's what you get inheriting code from someone who probably didn't have a clue.
Old 15 February 2008, 11:42 AM
  #6  
GazTheHat
Scooby Regular
Thread Starter
 
GazTheHat's Avatar
 
Join Date: Aug 2005
Location: 392/361 MY04 STi
Posts: 7,638
Likes: 0
Received 0 Likes on 0 Posts
Default

Originally Posted by Dracoro
use: (although you may need to use cell rather than range, I can't remember which in these cases, but you get the general idea etc....)
Worksheets("Sheet1").Range("O" & intRow + 2).Formula = InvoiceTotal
Worksheets("Sheet1").Range("O" & intRow + 2).Font.Bold = True
I tried:

Worksheets("Sheet1").Cell("O" & intRow + 2).Formula = InvoiceTotal

Object does not support that method error came up.
Old 15 February 2008, 11:59 AM
  #7  
Dracoro
Scooby Regular
 
Dracoro's Avatar
 
Join Date: Sep 2001
Location: A powerslide near you
Posts: 10,261
Likes: 0
Received 0 Likes on 0 Posts
Default

It's been a while. Try Cells (put the s in!) and use the up/down left/right. e.g. Cells(21, 4)

Range works though.
Worksheets("Sheet1").Range("O7").Font.Bold = True
Worksheets("Sheet1").Range("a3").Formula = "=1+4"

Just tested and ok.
Old 15 February 2008, 03:04 PM
  #8  
GazTheHat
Scooby Regular
Thread Starter
 
GazTheHat's Avatar
 
Join Date: Aug 2005
Location: 392/361 MY04 STi
Posts: 7,638
Likes: 0
Received 0 Likes on 0 Posts
Default

Yep, that range works, just amending the macro now.

There are 8 total columns, that are set to bold, could i just set the row to bold?

Maybe this:
Worksheets("Sheet1").Range("O").Font.Bold = True
Old 15 February 2008, 03:12 PM
  #9  
GazTheHat
Scooby Regular
Thread Starter
 
GazTheHat's Avatar
 
Join Date: Aug 2005
Location: 392/361 MY04 STi
Posts: 7,638
Likes: 0
Received 0 Likes on 0 Posts
Default

Scrap the above request. That was just being lazy. Googled it and found it.

Something like:

Rows(rowindex).EntrireRow.Font.Bold = True
Old 15 February 2008, 03:45 PM
  #10  
Dracoro
Scooby Regular
 
Dracoro's Avatar
 
Join Date: Sep 2001
Location: A powerslide near you
Posts: 10,261
Likes: 0
Received 0 Likes on 0 Posts
Default

Or use Range("O:O")

Either which way works.
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Sam Witwicky
Engine Management and ECU Remapping
17
13 November 2015 10:49 AM
Ganz1983
Subaru
5
02 October 2015 09:22 AM
thunder8
General Technical
0
01 October 2015 09:13 PM
Raptorman
ScoobyNet General
0
01 October 2015 06:46 PM
makkink
General Technical
10
01 October 2015 05:41 PM



Quick Reply: Excel - What function to convert text to a number?



All times are GMT +1. The time now is 03:39 AM.