I have a trigger cell which contains a value I am iterating between 0 and 170 degrees in 5 degree increments. As the value increases a number of different cells change throughout the spreadsheet which I want to paste to a table for each 5 degree increment. I have it working but I think there is a much more efficient way to do it. See code below:
Sub printforces()
' Define constants.
Const FIRST_NUMBER As Double = 0
Const LAST_NUMBER As Double = 170
Const STEP_NUMBER As Double = 5
' Reference the worksheet.
Dim ws As Worksheet: Set ws = ActiveSheet
' Reference the source cell.
Dim scell1 As Range: Set scell1 = ws.Range("K40")
Dim scell2 As Range: Set scell2 = ws.Range("K39")
Dim scell3 As Range: Set scell3 = ws.Range("O26")
Dim scell4 As Range: Set scell4 = ws.Range("P26")
Dim scell5 As Range: Set scell5 = ws.Range("O33")
Dim scell6 As Range: Set scell6 = ws.Range("P33")
' Reference the source trigger cell, a cell the values in the source range
' depend on.
Dim tcell As Range: Set tcell = ws.Range("N11")
' Reference the destination first cells.
Dim dfcell1 As Range: Set dfcell1 = ws.Range("S7")
Dim dfcell2 As Range: Set dfcell2 = ws.Range("V7")
Dim dfcell3 As Range: Set dfcell3 = ws.Range("Y7")
Dim dfcell4 As Range: Set dfcell4 = ws.Range("Z7")
Dim dfcell5 As Range: Set dfcell5 = ws.Range("AA7")
Dim dfcell6 As Range: Set dfcell6 = ws.Range("AB7")
' Reference the next destination cell.
' We need the first destination cell to build the destination range ('drg')
Dim dcell1 As Range: Set dcell1 = dfcell1
Dim dcell2 As Range: Set dcell2 = dfcell2
Dim dcell3 As Range: Set dcell3 = dfcell3
Dim dcell4 As Range: Set dcell4 = dfcell4
Dim dcell5 As Range: Set dcell5 = dfcell5
Dim dcell6 As Range: Set dcell6 = dfcell6
Dim i As Double
For i = FIRST_NUMBER To LAST_NUMBER Step STEP_NUMBER
' Trigger a change in the source range.
tcell.Value = i
' Write the new source max to the current destination cell.
dcell1.Value = (scell1)
dcell2.Value = (scell2)
dcell3.Value = (scell3)
dcell4.Value = (scell4)
dcell5.Value = (scell5)
dcell6.Value = (scell6)
' Reference the next destination cell (row).
Set dcell1 = dcell1.Offset(1)
Set dcell2 = dcell2.Offset(1)
Set dcell3 = dcell3.Offset(1)
Set dcell4 = dcell4.Offset(1)
Set dcell5 = dcell5.Offset(1)
Set dcell6 = dcell6.Offset(1)
Next i
End Sub
Can anyone give me some pointers?
The code works as it stands. Possibly an array would help but I’m not sure?