Forum Discussion

Wit_Emperor's avatar
Wit_Emperor
Copper Contributor
Apr 28, 2020

VBA HELP NEEDED

Please Help Me

 

I want a VBA so that I enter the starting number and the ending number and all the number between them gets autofilled. For example, I will type MDN001 in the starting box and MDN010 in the ending box and the number between them gets auto filled and gets transfered to a separate sheet.

 

Thanks in advance,

Regards,

Wit Emperor 

1 Reply

  • Haytham Amairah's avatar
    Haytham Amairah
    Silver Contributor

    Wit_Emperor

     

    Hi,

     

    Please try this one:

    Sub FillFromStartingToEnding()
        Dim starting As Integer
        Dim ending As Integer
    
        starting = Right(Range("B1").Value, 3)
        ending = Right(Range("B2").Value, 3)
    
        Range(Range("D2"), Range("D2").Offset(ending - 1, 0)).Select
        Selection.Value = "MDN"
        
        For Each cell In Selection
            cell.Value = cell.Value & Application.WorksheetFunction.Text(starting, "000")
            starting = starting + 1
        Next
    End Sub

     

    Hope that helps

Resources