Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
TJI TJI is offline
external usenet poster
 
Posts: 2
Default Problem using names as integer type

I have been trying to get some code working - the intent is to have the
program read through the column headers of a table and create a Worksheet
name to store the associated column name with the column number. This part of
the code works. But when I try to use the Worksheet name in the VBA code, I
keep getting a type mismatch.

'this assigns the Worksheet name of column 1 (happens to be "Serial") to the
integer value of 1:
Worksheets("Sheet1").Names.Add Name:=Worksheets("Sheet1").Cells(1, 1).Value,
RefersTo:=1

'this trys to access the column number to use in a calculation:
tempVal = Worksheets("Sheet1").Names("Serial").Value

tempVal is shown in the Locals as a variant/string and is equal to "=1",
which cannot be used in calculations.

Is there a way to get tempVal to be an integer which I can use in
calculations?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Problem using names as integer type

Use

tempVal = Worksheets("Sheet1").Range("Serial").Value


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"TJI" wrote in message
...
I have been trying to get some code working - the intent is to have the
program read through the column headers of a table and create a Worksheet
name to store the associated column name with the column number. This part

of
the code works. But when I try to use the Worksheet name in the VBA code,

I
keep getting a type mismatch.

'this assigns the Worksheet name of column 1 (happens to be "Serial") to

the
integer value of 1:
Worksheets("Sheet1").Names.Add Name:=Worksheets("Sheet1").Cells(1,

1).Value,
RefersTo:=1

'this trys to access the column number to use in a calculation:
tempVal = Worksheets("Sheet1").Names("Serial").Value

tempVal is shown in the Locals as a variant/string and is equal to "=1",
which cannot be used in calculations.

Is there a way to get tempVal to be an integer which I can use in
calculations?



  #3   Report Post  
Posted to microsoft.public.excel.programming
TJI TJI is offline
external usenet poster
 
Posts: 2
Default Problem using names as integer type

When I tried this, I got the following error:
"Run-time error'1004':
Application-defined or object-defined error"

If I go to the worksheet, I can type =Serial * 2 without an error ...

Tim.

"Bob Phillips" wrote:

Use

tempVal = Worksheets("Sheet1").Range("Serial").Value


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"TJI" wrote in message
...
I have been trying to get some code working - the intent is to have the
program read through the column headers of a table and create a Worksheet
name to store the associated column name with the column number. This part

of
the code works. But when I try to use the Worksheet name in the VBA code,

I
keep getting a type mismatch.

'this assigns the Worksheet name of column 1 (happens to be "Serial") to

the
integer value of 1:
Worksheets("Sheet1").Names.Add Name:=Worksheets("Sheet1").Cells(1,

1).Value,
RefersTo:=1

'this trys to access the column number to use in a calculation:
tempVal = Worksheets("Sheet1").Names("Serial").Value

tempVal is shown in the Locals as a variant/string and is equal to "=1",
which cannot be used in calculations.

Is there a way to get tempVal to be an integer which I can use in
calculations?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Problem using names as integer type

Dim tempVal as Long ' or Integer if you prefer

tempVal = Evaluate(Worksheets("Sheet1").Range("Serial").Refe rsto)

--
Regards,
Tom Ogilvy


"TJI" wrote in message
...
When I tried this, I got the following error:
"Run-time error'1004':
Application-defined or object-defined error"

If I go to the worksheet, I can type =Serial * 2 without an error ...

Tim.

"Bob Phillips" wrote:

Use

tempVal = Worksheets("Sheet1").Range("Serial").Value


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"TJI" wrote in message
...
I have been trying to get some code working - the intent is to have

the
program read through the column headers of a table and create a

Worksheet
name to store the associated column name with the column number. This

part
of
the code works. But when I try to use the Worksheet name in the VBA

code,
I
keep getting a type mismatch.

'this assigns the Worksheet name of column 1 (happens to be "Serial")

to
the
integer value of 1:
Worksheets("Sheet1").Names.Add Name:=Worksheets("Sheet1").Cells(1,

1).Value,
RefersTo:=1

'this trys to access the column number to use in a calculation:
tempVal = Worksheets("Sheet1").Names("Serial").Value

tempVal is shown in the Locals as a variant/string and is equal to

"=1",
which cannot be used in calculations.

Is there a way to get tempVal to be an integer which I can use in
calculations?






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I add an integer to an existing integer? Aaron Excel Worksheet Functions 3 December 17th 09 09:46 PM
How to type in customers' names & addresses to print mail labels? Ammable Excel Discussion (Misc queries) 1 October 28th 06 08:09 PM
random integer problem. mark_varney47[_6_] Excel Programming 1 December 6th 05 02:58 PM
Problem with Solver and Integer constraints [email protected] Excel Worksheet Functions 1 August 12th 05 03:23 AM
linerar/integer programming problem ben h Excel Programming 3 December 22nd 03 12:46 PM


All times are GMT +1. The time now is 07:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"