vba code for finding the ranges between 2 cols

  • Thread starter Thread starter tom
  • Start date Start date
T

tom

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
 
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
 
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
 
add the indicated line:


tom said:
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
 
Back
Top