Question regarding us a for next loop for inputting data into a column

zoog25

Active Member
Joined
Nov 21, 2011
Messages
376
Hello all here is a question

Say for example i have 2 cells an a column. B2, C2 and column A. Now in B2 i have "p101 and C2 I have "p130". These two are the start and end of a range of numbers from p101 to p130. Each number to be put into column A so A1 = p101 and A30 = p130. Now I now by dragging down, excel does this, but i want to use a vba code because when i have to do it multiple times it gets a little confussing. Please help.
 

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

DeBeuz

Active Member
Joined
Jun 6, 2012
Messages
448
Hi,

Try something like this:
Code:
Option Explicit


Sub Create_list()
    Dim C As Long
    Dim E As Integer
    Dim Prefix As String
    Dim R As Long
    Dim S As Integer
    Dim Splitpoint As Integer
    Dim Work As String
    
    'Get start
    Work = Range("B2").Value
    'Find splitpoint
    Splitpoint = Len(Work)
    While IsNumeric(Mid(Work, Splitpoint, 1))
        Splitpoint = Splitpoint - 1
    Wend
    Prefix = Mid(Work, 1, Splitpoint)
    S = CInt(Mid(Work, Splitpoint + 1))
    E = CInt(Mid(Range("C2").Value, Splitpoint + 1))
    R = 1
    For C = S To E
        Range("A" & R).Value = Prefix & C
        R = R + 1
    Next C
End Sub

Paul
 

Watch MrExcel Video

Forum statistics

Threads
1,122,193
Messages
5,594,774
Members
413,934
Latest member
austinb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top