Decatron
07-11-2023, 10:02 AM
Dim x As Long
Sub savefile()
Dim rng As Range, c As Long
Set rng = Sheet2.Range("A2:A8")
c = rng.Cells.Count
If x = c Then
x = 1
Else
x = x + 1
End If
Range("D10") = rng(x)
End Sub
This program code prints the subsequent value from a list of items each time the macro runs. However, it does not save the index of the last value to 'x' before closing the file. Therefore, 'x' starts from the first item on the list on running the macro upon reopening the file. Please suggest a way to save the index of the last list item to the variable 'x' that was inserted using the macro, so that on reopening of the file, the list continues from where it had been left.
For example, suppose ten items from the list were inserted using the macro before closing the file. On running the macro upon reopening of the file, the eleventh item has be inserted and so on.
Sub savefile()
Dim rng As Range, c As Long
Set rng = Sheet2.Range("A2:A8")
c = rng.Cells.Count
If x = c Then
x = 1
Else
x = x + 1
End If
Range("D10") = rng(x)
End Sub
This program code prints the subsequent value from a list of items each time the macro runs. However, it does not save the index of the last value to 'x' before closing the file. Therefore, 'x' starts from the first item on the list on running the macro upon reopening the file. Please suggest a way to save the index of the last list item to the variable 'x' that was inserted using the macro, so that on reopening of the file, the list continues from where it had been left.
For example, suppose ten items from the list were inserted using the macro before closing the file. On running the macro upon reopening of the file, the eleventh item has be inserted and so on.