如何在一个范围内插入下一个工作日的数据

时间:2015-04-13 14:20:42

标签: vba excel-vba excel

我需要更改“投资组合+以下工作日数据”范围内所有单元格的值。因此,例如,今天我需要将我的范围值作为“portfolio05042015”。我已经设置了你的范围,你可以看到

Sub SelectNonBlanks()
Dim rng As Range

Set rng = Range("A1:A10000")
rng.SpecialCells(xlCellTypeConstants).Select
End Sub

所以现在,我只需要改变他们的价值观。我将衷心感谢您的帮助 谢谢

2 个答案:

答案 0 :(得分:0)

您可以为所选范围指定值,例如:

Selection.Value = "portfolio" & Format(Now, "ddmmyyyy")

如果您想要下一个工作日,您可以使用此功能或使用谷歌找到一些东西:

Function NextWorkday()

Select Case Weekday(Now, vbMonday) ' - Monday is first day of work you can change this for example for vbSunday. In this example every Saturday and Sunday are holiday
Case 5
NextWorkday = Now + 3
Case 6
NextWorkday = Now + 2
Case Else
NextWorkday = Now + 1
End Select

Holidays = Array("14042015", "16042015") 'your holidays list, format ddmmyyyy

Index = 0

For Each ArrMember In Holidays
    If Format(NextWorkday, "ddmmyyyy") = Holidays(Index) Then
    NextWorkday = NextWorkday + 1
    End If
Index = Index + 1
Next

NextWorkday = Format(NextWorkday, "ddmmyyyy")
End Function

具有NextWorkday功能的子

Sub SelectNonBlanks()
Dim rng As Range

Set rng = Range("A1:A10000")
rng.SpecialCells(xlCellTypeConstants).Select

Selection.Value = "portfolio" & NextWorkday

End Sub

答案 1 :(得分:0)

如果您的选择正确:

For Each myCell In Selection
    myCell.Value = CStr(myCell.Value) & " " & CStr(Format(Date, "ddmmyyyy"))
Next myCell