我有3列(K:M)的数据,我希望根据“AA”列中的日期值将其移动到相应的列N:Y。另外,我希望K:M中的移动数据可以通过值列“J”进行调整,给定最左边的K:M列不是空白。换句话说,我希望列“J”与列K:M中最左边的<>“”值相加。然后,我需要根据“AA”列中的日期值将数据移动到N:Y列。使用粗体代码时遇到问题,因为没有调整范围内最左边的值。
Sub MoveData()
'
'
rspn = MsgBox("Are you Sure?", vbYesNo)
If rspn = vbNo Then Exit Sub
'code
ActiveWindow.SmallScroll Down:=-27
Range("N3:Y502").Select
Selection.ClearContents
Range("N3").Select
Range("N3:Y502").Interior.Color = xlNone
Dim colOffset As Integer, dataCols As Long
Dim datesRng As Range, dateRng As Range, valsRng As Range
With ThisWorkbook.Worksheets("2016 ACTIVE")
Set datesRng = .Range("AA3:AA" & .Cells(.Rows.Count, "AA").End(xlUp).Row).SpecialCells(xlCellTypeConstants, xlNumbers)
For Each dateRng In datesRng
With .Range("K" & dateRng.Row)
dataCols = WorksheetFunction.CountA(.Resize(, 3))
Set valsRng = .Offset(, 3 - dataCols).Resize(, dataCols)
End With
colOffset = WorksheetFunction.Min(Month(dateRng), Month(Date)) - dataCols
If colOffset >= 0 Then
.Range("N" & dateRng.Row).Offset(, colOffset).Resize(, dataCols).Value = valsRng.Value
.Range("N" & dateRng.Row).Offset(, colOffset).Value = .Range("N" & dateRng.Row).Offset(, colOffset) - .Range("J" & dateRng.Row).Value
Else
End If
Next dateRng
End With
MsgBox "Operation Completed"
End Sub