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

I am writting a function and the user needs to select a range for the x
values. If the user selected, say, the range "A1:A2" then

x1 = rng(1)
x2 = rng(2)

If the range "B2:B4", then
x1 = rng(1)
x2 = rng(2)
x3 = rng(3)

I wrote this code to carry out the above task

NoOfRowsSelected = rng.Rows.Count

For i = 1 To NoOfRowsSelected
namex = "x" & i
namex = rng(i).value
Next i

The code is only working for i = 3. In other words, it does not give the
right values for x1, x2, x4, .....

Can anybody help?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Range problem

Ali,

Dim rng As Range
Dim i As Integer

Set rng = Selection
For i = 1 To rng.Rows.Count
MsgBox "x" & i & " is equal to " & rng.Cells(i).Value
Next i

You could also use the Application.Inputbox method to get the user to select
the cells.

HTH,
Bernie
MS Excel MVP


"Ali Baba" wrote in message
...
I am writting a function and the user needs to select a range for the x
values. If the user selected, say, the range "A1:A2" then

x1 = rng(1)
x2 = rng(2)

If the range "B2:B4", then
x1 = rng(1)
x2 = rng(2)
x3 = rng(3)

I wrote this code to carry out the above task

NoOfRowsSelected = rng.Rows.Count

For i = 1 To NoOfRowsSelected
namex = "x" & i
namex = rng(i).value
Next i

The code is only working for i = 3. In other words, it does not give the
right values for x1, x2, x4, .....

Can anybody help?



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
Problem with range [email protected] Excel Discussion (Misc queries) 7 February 14th 07 04:06 PM
Range problem David Gerstman Excel Programming 2 May 24th 05 07:11 PM
getting value of range problem Grant Excel Programming 1 September 23rd 04 06:20 AM
range problem [email protected] Excel Programming 1 April 9th 04 09:47 AM
Range problem Mark[_36_] Excel Programming 6 February 12th 04 01:22 PM


All times are GMT +1. The time now is 12:20 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"