View Single Post
 
Old 03-18-2018, 04:31 PM
NoSparks NoSparks is offline Windows 7 64bit Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

Knowing you'll be using a button simplifies things.
Completely delete that previous event code from the sheet module and paste this into the button assignment.
Code:
Sub Button1_Click()

Dim i As Integer, str As String

'clear anything existing in N
Cells(4, "N").ClearContents
'make sure both cells have numbers
If Not IsNumeric(Cells(4, "L")) Or Not IsNumeric(Cells(4, "M")) Then Exit Sub
'make sure L cell is smaller than M cell
If Cells(4, "L") >= Cells(4, "M") Then Exit Sub
'put together what's to go into N
    For i = Cells(4, "L").Value To Cells(4, "M").Value
        str = str & ";" & i
    Next i
'write the string to N, remove the leading ;
Cells(4, "N").Value = Mid(str, 2)

End Sub
Macros that are Private do not show in the macro dialogue.
Neither do any with parameters within the brackets.
This is good to know because with no sheet names used code always uses the active sheet.
No problem when run from the button on the sheet but you probably don't want somebody accidentally running it from the macro dialogue when a different sheet is active.

Hope this helps.
Reply With Quote