InputF9repeat
New Member
- Joined
- Apr 19, 2021
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
Hi, I'm trying to adapt the VBA code from this thread into a loop. The aim is to copy and paste a range of cells (Name Range "Output") for each scenario that I'm running into a numbered list (Name Range "Paste.Index").
There are 10 scenarios that are numbered 1-10 (Name Range "NumScenarios") and whichever scenario is chosen is shown in the cell (Name Range "ActiveScenario"). My intention is for the macro to cycle through each of the 10 scenarios and then copy and paste values for each scenario based on the location in the list for that scenario. So for example, if scenario 5 is active, then the macro would copy "Output" and then paste the values next to where the number 5 appears in a list. For some reason the code refuses to paste anything past scenario 6 and it pastes over some of the older pasted values for some reason.
Any help would be greatly appreciated.
There are 10 scenarios that are numbered 1-10 (Name Range "NumScenarios") and whichever scenario is chosen is shown in the cell (Name Range "ActiveScenario"). My intention is for the macro to cycle through each of the 10 scenarios and then copy and paste values for each scenario based on the location in the list for that scenario. So for example, if scenario 5 is active, then the macro would copy "Output" and then paste the values next to where the number 5 appears in a list. For some reason the code refuses to paste anything past scenario 6 and it pastes over some of the older pasted values for some reason.
Any help would be greatly appreciated.
VBA Code:
Public Sub UpdateScenarios()
Dim intCount As Integer
Application.Calculation = xlCalculationAutomatic
For intCount = 1 To Range("NumScenarios").Count - 1
Range("ActiveScenario").Value = intCount
CallCopyPaste
Next intCount
End Sub
Sub CopyPaste()
FindItem = Range("ActiveScenario").Value
FoundItem = Range("Paste.Index").Find(What:=FindItem).Address
PasteLocation = Range(FoundItem).Offset(1, 7).Address
Range("Output").Copy
Range(PasteLocation).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End Sub