D
Dave Peterson
If you really care about the cells that you skipped...
Option Explicit
Sub testme()
Dim myDate As String
Dim myMonth As Long
Dim DestSheet As Worksheet
Dim DestRng As Range
Dim OrigRng As Range
Dim gCtr As Long 'groupCounter
Dim DestAddr As Variant
Dim HowMany As Variant
Dim FromRow As Variant
Dim wks As Worksheet
'what sheet is getting these values?
Set wks = ActiveSheet
'six groups starting in
'ai7, ai16, ai21, ai28, ai33, ai38
'for this many cells
' 8, 4, 6, 4, 3, 5
'starting in rows
' 5, 14, 19, 26, 31, 35
DestAddr = Array("ai7", "ai16", "ai21", "ai28", "ai33", "ai38")
FromRow = Array(5, 14, 19, 26, 31, 35)
HowMany = Array(8, 4, 6, 4, 3, 5)
If UBound(DestAddr) = UBound(HowMany) _
And UBound(FromRow) = UBound(HowMany) Then
'whew, they match!
Else
MsgBox "Design error -- contact Carlee @ xxxx"
Exit Sub
End If
myDate = Trim(Worksheets(DestSheet).Range("B4").Value)
myDate = myDate & " 1, 2000"
If IsDate(myDate) = False Then
MsgBox "Not a month in B4 of " & DestSheet
Exit Sub
Else
myMonth = Month(myDate)
End If
For gCtr = LBound(DestAddr) To UBound(DestAddr)
Set DestRng = wks.Range(DestAddr).Resize(HowMany(gCtr), 1)
Set OrigRng = Worksheets("Year at a Glance") _
.Cells(FromRow, "B").Offset(0, myMonth) _
.Resize(HowMany(gCtr), 1)
DestRng.Value = OrigRng.Value
Next gCtr
End Sub
Untested, but it did compile.
Option Explicit
Sub testme()
Dim myDate As String
Dim myMonth As Long
Dim DestSheet As Worksheet
Dim DestRng As Range
Dim OrigRng As Range
Dim gCtr As Long 'groupCounter
Dim DestAddr As Variant
Dim HowMany As Variant
Dim FromRow As Variant
Dim wks As Worksheet
'what sheet is getting these values?
Set wks = ActiveSheet
'six groups starting in
'ai7, ai16, ai21, ai28, ai33, ai38
'for this many cells
' 8, 4, 6, 4, 3, 5
'starting in rows
' 5, 14, 19, 26, 31, 35
DestAddr = Array("ai7", "ai16", "ai21", "ai28", "ai33", "ai38")
FromRow = Array(5, 14, 19, 26, 31, 35)
HowMany = Array(8, 4, 6, 4, 3, 5)
If UBound(DestAddr) = UBound(HowMany) _
And UBound(FromRow) = UBound(HowMany) Then
'whew, they match!
Else
MsgBox "Design error -- contact Carlee @ xxxx"
Exit Sub
End If
myDate = Trim(Worksheets(DestSheet).Range("B4").Value)
myDate = myDate & " 1, 2000"
If IsDate(myDate) = False Then
MsgBox "Not a month in B4 of " & DestSheet
Exit Sub
Else
myMonth = Month(myDate)
End If
For gCtr = LBound(DestAddr) To UBound(DestAddr)
Set DestRng = wks.Range(DestAddr).Resize(HowMany(gCtr), 1)
Set OrigRng = Worksheets("Year at a Glance") _
.Cells(FromRow, "B").Offset(0, myMonth) _
.Resize(HowMany(gCtr), 1)
DestRng.Value = OrigRng.Value
Next gCtr
End Sub
Untested, but it did compile.