Option Explicit
Sub Macro3()
Dim objSourceTab As Object, _
objDestinTab As Object
Dim lngLoopCount As Long, _
lngRowOutput As Long
Set objSourceTab = Sheets("Sheet1") 'Tab name with minimum and maximum limits. Change to suit.
Set objDestinTab = Sheets("Sheet2") 'Tab name for output. Change to suit.
'Ensure there has been a minimum (cell G6) and a maximum (cell H6) entered.
If Len(objSourceTab.Range("G6")) = 0 Then
MsgBox "There is no minmum value entered.", vbInformation, "Value List Editor"
Exit Sub
ElseIf Len(objSourceTab.Range("H6")) = 0 Then
MsgBox "There is no maximum value entered.", vbInformation, "Value List Editor"
Exit Sub
End If
lngRowOutput = 2
Application.ScreenUpdating = False
For lngLoopCount = objSourceTab.Range("G6").Value To objSourceTab.Range("H6").Value
If lngRowOutput = 0 Then
lngRowOutput = 2 'Initial row number output. Change to suit.
Else
lngRowOutput = lngRowOutput + 1
End If
objDestinTab.Range("A" & lngRowOutput).Value = lngLoopCount 'Output to Col A. Change to suit
Next lngLoopCount
Application.ScreenUpdating = True
End Sub
Option Explicit
Sub Macro4()
Dim objSourceTab As Object, _
objDestinTab As Object
Set objSourceTab = Sheets("Sheet1") 'Tab name with minimum and maximum limits. Change to suit.
Set objDestinTab = Sheets("Sheet2") 'Tab name for output. Change to suit.
'Ensure there has been a minimum (cell G6) and a maximum (cell H6) entered.
If Len(objSourceTab.Range("G6")) = 0 Then
MsgBox "There is no minmum value entered.", vbInformation, "Value List Editor"
Exit Sub
ElseIf Len(objSourceTab.Range("H6")) = 0 Then
MsgBox "There is no maximum value entered.", vbInformation, "Value List Editor"
Exit Sub
End If
Application.ScreenUpdating = False
'Copy the formula down from A2
'Note while you can adjust the following formula output to any Column, the minimum Row number is 2.
With objDestinTab.Range("A2:A" & objSourceTab.Range("H6").Value - objSourceTab.Range("G6").Value + 2)
.Formula = "=IF(ROW()=2,Sheet1!G6,A1+1)"
'Converts the above formula range to values. Comment out if not required.
.Value = .Value
End With
Application.ScreenUpdating = True
End Sub
And here's a more efficient way:
Code:Option Explicit Sub Macro4() Dim objSourceTab As Object, _ objDestinTab As Object Set objSourceTab = Sheets("Sheet1") 'Tab name with minimum and maximum limits. Change to suit. Set objDestinTab = Sheets("Sheet2") 'Tab name for output. Change to suit. 'Ensure there has been a minimum (cell G6) and a maximum (cell H6) entered. If Len(objSourceTab.Range("G6")) = 0 Then MsgBox "There is no minmum value entered.", vbInformation, "Value List Editor" Exit Sub ElseIf Len(objSourceTab.Range("H6")) = 0 Then MsgBox "There is no maximum value entered.", vbInformation, "Value List Editor" Exit Sub End If Application.ScreenUpdating = False 'Copy the formula down from A2 'Note while you can adjust the following formula output to any Column, the minimum Row number is 2. With objDestinTab.Range("A2:A" & objSourceTab.Range("H6").Value - objSourceTab.Range("G6").Value + 2) .Formula = "=IF(ROW()=2,Sheet1!G6,A1+1)" 'Converts the above formula range to values. Comment out if not required. .Value = .Value End With Application.ScreenUpdating = True End Sub
HTH
Robert