Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tom tom is offline
external usenet poster
 
Posts: 570
Default vba code for finding the ranges between 2 cols


I have 2 columns A,B with values; i have to list out the values between A1,B1
including A1, B1 after that it should move to row2.....so on.I have to get
the answer the which is mentioned in C column. Please suggest. I tried but
inner loop is not working for me.

A B C

4 7 5
9 11 6
19 21 7
53 59 9
61 65 10
11
19
20
21
53
54
59
61
62
63
64
65




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default vba code for finding the ranges between 2 cols


Sub GetNumbers()

RowCount = 1
NewRow = 1
Do While Range("A" & RowCount) < ""
FirstNum = Range("A" & RowCount)
LastNum = Range("B" & RowCount)
For i = FirstNum To LastNum
Range("C" & NewRow) = i
NewRow = NewRow + 1
Next i
RowCount = RowCount + 1
Loop


End Sub


"tom" wrote:

I have 2 columns A,B with values; i have to list out the values between A1,B1
including A1, B1 after that it should move to row2.....so on.I have to get
the answer the which is mentioned in C column. Please suggest. I tried but
inner loop is not working for me.

A B C

4 7 5
9 11 6
19 21 7
53 59 9
61 65 10
11
19
20
21
53
54
59
61
62
63
64
65




  #3   Report Post  
Posted to microsoft.public.excel.programming
tom tom is offline
external usenet poster
 
Posts: 570
Default vba code for finding the ranges between 2 cols

The below coding working fine but if b1 is blank in this case c1 should
display A1 like below.Please suggest.

A1 B1 C1

19 20 19
25 20
25

"Joel" wrote:

Sub GetNumbers()

RowCount = 1
NewRow = 1
Do While Range("A" & RowCount) < ""
FirstNum = Range("A" & RowCount)
LastNum = Range("B" & RowCount)
For i = FirstNum To LastNum
Range("C" & NewRow) = i
NewRow = NewRow + 1
Next i
RowCount = RowCount + 1
Loop


End Sub


"tom" wrote:

I have 2 columns A,B with values; i have to list out the values between A1,B1
including A1, B1 after that it should move to row2.....so on.I have to get
the answer the which is mentioned in C column. Please suggest. I tried but
inner loop is not working for me.

A B C

4 7 5
9 11 6
19 21 7
53 59 9
61 65 10
11
19
20
21
53
54
59
61
62
63
64
65




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default vba code for finding the ranges between 2 cols

add the indicated line:

RowCount = 1
NewRow = 1
Do While Range("A" & RowCount) < ""
FirstNum = Range("A" & RowCount)
LastNum = Range("B" & RowCount)

IF LastNum= 0 then LastNum = FirstNum 'ADD THIS
For i = FirstNum To LastNum
Range("C" & NewRow) = i
NewRow = NewRow + 1
Next i
RowCount = RowCount + 1
Loop



"tom" wrote in message
...
The below coding working fine but if b1 is blank in this case c1 should
display A1 like below.Please suggest.

A1 B1 C1

19 20 19
25 20
25

"Joel" wrote:

Sub GetNumbers()

RowCount = 1
NewRow = 1
Do While Range("A" & RowCount) < ""
FirstNum = Range("A" & RowCount)
LastNum = Range("B" & RowCount)
For i = FirstNum To LastNum
Range("C" & NewRow) = i
NewRow = NewRow + 1
Next i
RowCount = RowCount + 1
Loop


End Sub


"tom" wrote:

I have 2 columns A,B with values; i have to list out the values between
A1,B1
including A1, B1 after that it should move to row2.....so on.I have to
get
the answer the which is mentioned in C column. Please suggest. I tried
but
inner loop is not working for me.

A B C

4 7 5
9 11 6
19 21 7
53 59 9
61 65 10
11
19
20
21
53
54
59
61
62
63
64
65




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
Enhance sub to copy cols of variable length into 1 col to snake results into other cols Max Excel Programming 1 August 7th 08 02:03 PM
Change code to popualte into cols D,E, & F instead of A,B, & C BZeyger Excel Programming 0 October 30th 07 09:59 PM
2 Cols To 2 Cols VLookup Comparison CuriousMe Excel Discussion (Misc queries) 4 December 21st 06 07:54 PM
Range.Select 1st pass 13 cols, 2nd paqss 25 cols twice as wide in error? Craigm[_53_] Excel Programming 2 May 2nd 06 11:04 AM
Cond Format:re color 2 cols, skip 2 cols Tat Excel Worksheet Functions 2 June 22nd 05 06:43 PM


All times are GMT +1. The time now is 10:19 AM.

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"