English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Presently, this one works, but there must be an easier way?!

Dim z As Integer
Dim rge As String
Dim rgestr As String
Dim shortened As String
Dim howmany As Integer
'
z = 5
rgestr = Str(z)
howmany = Len(rgestr)
shortened = Right(z, howmany - 1)
rge = "A" + shortened
Range(rge).Select
'
' and so on ........

2006-09-05 02:16:19 · 5 answers · asked by Marianna 6 in Computers & Internet Programming & Design

Clarification: I want to address a cell in Excel using an indirect method because I will use a loop.
The problem is that "A"+str(5) causes a space between the A and the 5. (btw: using & instead of + has the same result.

2006-09-05 02:29:44 · update #1

5 answers

You don't need to make z into a String. Just put directly into the formula as shown below. In this formula, cell A5 will be set to 30.

Dim z As Integer
z = 5
Range("A" & z).Value = 30
End Sub

2006-09-05 03:22:12 · answer #1 · answered by Mendelson 2 · 0 0

People gave solutions, but nobody said why.

It goes back to the days of Megasloth's Quickbasic. They and they alone in their "infinite wisdom" (pffft!) decided to always leave a blank space in front of positive numbers. No other BASIC interpreters or compilers did this.

It was done so that positive and negative numbers would require the same number of characters to display a number and that decimals would line up. The problem is, though, it's harder to remove a blank from a number than it is to add one. They should have left it to programmers to add a space *if* it is needed. Most of the time, you don't want it, and programmers were left to contend with the mess.

Obviously, Mr. Bill decided to carry over his stupidity from QuickBasic to Windows....

2006-09-05 11:49:04 · answer #2 · answered by Anonymous · 0 0

cant use + use an & instead

rge= "A" & shortened

i am also a little confuse on what you are trying to do? are you removing spaces or just taking the last character from a string?

2006-09-05 09:19:23 · answer #3 · answered by Nick H 3 · 1 0

Use & with strings and Trim Function to remove leading and ending spaces.

rge="A" & trim(rgestr)

2006-09-05 10:14:40 · answer #4 · answered by tazintampa 3 · 0 0

instead of using 'A'+ Str(5) use:

'A' + Trim( Str(5) )

2006-09-05 10:30:02 · answer #5 · answered by IsaacArsenal 3 · 0 0

fedest.com, questions and answers