Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Assignment problem

I would like cells A1, A2 etc to populate with "Error 1", "Error 2"
etc. However when I use this:

Sub test()

E1 = "Error 1"
E2 = "Error 2"

For i = 1 To 2
Range("a" & i) = "E" & i
Next i

End Sub

I get "E1", "E2 as a result. I know I am making a silly goof and help
would be greatly appreciated.

Thanks
Utkarsh

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Assignment problem

You could just do this:

Sub test()
For i = 1 To 2
Range("a" & i) = "Error " & i
Next i
End Sub

But I think you're trying to do this:

Sub test2()
Dim i As Long
Dim E(1 To 2) As String

E(1) = "Error 1"
E(2) = "Error 2"
For i = 1 To 2
Range("a" & i) = E(1)
Next i
End Sub

VBA won't allow you to build variable names on the fly (like some other
languages) like you originally wanted.



wrote:

I would like cells A1, A2 etc to populate with "Error 1", "Error 2"
etc. However when I use this:

Sub test()

E1 = "Error 1"
E2 = "Error 2"

For i = 1 To 2
Range("a" & i) = "E" & i
Next i

End Sub

I get "E1", "E2 as a result. I know I am making a silly goof and help
would be greatly appreciated.

Thanks
Utkarsh


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Assignment problem


Thanks Dave!!
It was the second solution that I was looking for.

Also, you are right about programming languages. Switching between them
causes many a heartache!

Utkarsh

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Assignment problem

You probably meant
Range("a" & i) = E(1)

should be

Range("a" & i) = E(i)

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
You could just do this:

Sub test()
For i = 1 To 2
Range("a" & i) = "Error " & i
Next i
End Sub

But I think you're trying to do this:

Sub test2()
Dim i As Long
Dim E(1 To 2) As String

E(1) = "Error 1"
E(2) = "Error 2"
For i = 1 To 2
Range("a" & i) = E(1)
Next i
End Sub

VBA won't allow you to build variable names on the fly (like some other
languages) like you originally wanted.



wrote:

I would like cells A1, A2 etc to populate with "Error 1", "Error 2"
etc. However when I use this:

Sub test()

E1 = "Error 1"
E2 = "Error 2"

For i = 1 To 2
Range("a" & i) = "E" & i
Next i

End Sub

I get "E1", "E2 as a result. I know I am making a silly goof and help
would be greatly appreciated.

Thanks
Utkarsh


--

Dave Peterson



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 430
Default Assignment problem

I think this is what you need as you first intended ...
Starting with a blank worksheet run this standard code:

Sub test()
Range("E1") = "Error 1"
Range("E2") = "Error 2"
For i = 1 To 2
Range("a" & i) = Range("E" & i)
Next i
End Sub

HTH


"Utkarsh Majmudar" wrote in message
...

Thanks Dave!!
It was the second solution that I was looking for.

Also, you are right about programming languages. Switching between them
causes many a heartache!

Utkarsh

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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
Picture # assignment danpt Excel Discussion (Misc queries) 9 April 4th 09 10:59 PM
Number Assignment GRK Excel Worksheet Functions 3 April 26th 08 12:31 AM
Key Assignment Log Norma Excel Discussion (Misc queries) 0 May 12th 05 04:10 PM
assignment problem L. Chung Excel Worksheet Functions 1 April 17th 05 06:06 AM
Assignment Statement richard daniels Excel Programming 0 August 29th 03 09:57 AM


All times are GMT +1. The time now is 08:56 PM.

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

About Us

"It's about Microsoft Excel"