View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
dkinn dkinn is offline
external usenet poster
 
Posts: 30
Default convert string to integer

What version of Excel are you using?
I've got 2003 and the following code retrives the sheet name (which I've
renamed to the number 1) and then adds 1 and it comes up with the value of 2
and then adds a new sheet named 2

x = Sheets(1).Name
x = x + 1
Sheets.Add.Name = x

even if I start with

Dim x As String

VBA converts the string 1 to a value when I try to add 1 to the value

Is there something else going on with your code that might be causing a
problem here?

also one way to convert your number to a string is
y = Str(3)

or simply use the & function to join strings such as

y & "my text string"

both should convert a number to a string

hope this helps

David
"eugene" wrote:

Hi,

Simple question.

Part of my workbook has numbered sheets (1,2, etc. - it has others as well).
I would like to add sheets using a macro, calling them by the next number in
the sequence - eg if the last sheet is 10, the next sheets should be named
11, 12, etc. (Sheets.Count for the last sheet is not the same as its name
and can vary from workbook to workbook).

If I capture the name of the last sheet (Sheets.Name), the macro deals with
it as a string and thus I am encountering a problem raising its value. How
does one do arithmetic on a string or more specifically, how does one convert
a string into a number?

Conversely, how would one change a number into a string (not needed for
this macro, but generally useful to know)?

---
Eugene