goldenvision
Board Regular
- Joined
- Jan 13, 2004
- Messages
- 234
I'm looking for some tips on how best to streamline the below portion of code.
I have it working for one worksheet ("BA Bush"). I now need to repeat this for another 16 sheets and I want to move away from having pages and pages of repeating commands. I have seen some quite nice code on this forum and I was looking for some pointers on how best to streamline this.
Thanks in advance.
In a nutshell the code is reading cell A1 which contains the current month, then dependant on that value, copies the formula from cells D4:E8 to upto 17 other cells.
I have it working for one worksheet ("BA Bush"). I now need to repeat this for another 16 sheets and I want to move away from having pages and pages of repeating commands. I have seen some quite nice code on this forum and I was looking for some pointers on how best to streamline this.
Thanks in advance.
In a nutshell the code is reading cell A1 which contains the current month, then dependant on that value, copies the formula from cells D4:E8 to upto 17 other cells.
Code:
Sub CopyFormulas()
'copy summary formula across BA Bush
Sheets("BA Bush").Activate
Range("D4:E8").Select
Selection.Copy
If Range("A1").Value = "01/08/2007" Then
Range("F4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/09/2007" Then
Range("F4, H4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/10/2007" Then
Range("F4, H4, J4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/11/2007" Then
Range("F4, H4, J4, L4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/12/2007" Then
Range("F4, H4, J4, L4, N4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/01/2008" Then
Range("F4, H4, J4, L4, N4, P4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/02/2008" Then
Range("F4, H4, J4, L4, N4, P4, R4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/03/2008" Then
Range("F4, H4, J4, L4, N4, P4, R4, T4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/04/2008" Then
Range("F4, H4, J4, L4, N4, P4, R4, T4, V4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/05/2008" Then
Range("F4, H4, J4, L4, N4, P4, R4, T4, V4, X4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/06/2008" Then
Range("F4, H4, J4, L4, N4, P4, R4, T4, V4, X4, Z4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/07/2008" Then
Range("F4, H4, J4, L4, N4, P4, R4, T4, V4, X4, Z4, AB4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/08/2008" Then
Range("F4, H4, J4, L4, N4, P4, R4, T4, V4, X4, Z4, AB4, AD4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/09/2008" Then
Range("F4, H4, J4, L4, N4, P4, R4, T4, V4, X4, Z4, AB4, AD4, AF4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/10/2008" Then
Range("F4, H4, J4, L4, N4, P4, R4, T4, V4, X4, Z4, AB4, AD4, AF4, AH4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/11/2008" Then
Range("F4, H4, J4, L4, N4, P4, R4, T4, V4, X4, Z4, AB4, AD4, AF4, AH4, AJ4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
If Range("A1").Value = "01/12/2008" Then
Range("F4, H4, J4, L4, N4, P4, R4, T4, V4, X4, Z4, AB4, AD4, AF4, AH4, AJ4, AK4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Else
End If '08/07
End If '09/07
End If '10/07
End If '11/07
End If '12/07
End If '01/08
End If '02/08
End If '03/08
End If '04/08
End If '05/08
End If '06/08
End If '07/08
End If '08/08
End If '09/08
End If '10/08
End If '11/08
End If '12/08
End Sub