ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vba code for finding the ranges between 2 cols (https://www.excelbanter.com/excel-programming/430693-vba-code-finding-ranges-between-2-cols.html)

tom

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





joel

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





tom

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





Patrick Molloy

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






All times are GMT +1. The time now is 02:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com