我有超过 4 列的数据,第一列“A”作为日期列,然后以下列“B、C、D”作为数据。我正在尝试创建一个宏,它将搜索周末日期并将它们添加到星期一的数据中,然后从整体数据中删除周末日期和数据。到目前为止,这是我的代码:
Sub NamedRange()
Dim Rng1 As Range
Dim newDate As Integer
Dim NumberOfRows As Range
Dim MyRange As Range
Dim lastRow2 As Variant
Set Rng1 = Sheets("Sheet1").Range("A1:A20")
Dim date1 As String
Dim dat As Date
Dim newPrice As Double
Set RgSales = Range("MyRange")
For i = 1 To RgSales.Rows.Count
For j = 1 To RgSales.Columns.Count
dat = RgSales.Cells(i, j)
date1 = WeekdayName(Weekday(dat))
If (date1 = "Saturday" Or date1 = "Sunday") Then
newDate = (RgSales.Cells(i + 1, j + 1).Value) + (RgSales.Cells(i, j + 1).Value)
RgSales.Cells(i + 1, j + 1).Value = newDate
newPrice = (RgSales.Cells(i + 1, j + 2).Value) + (RgSales.Cells(i, j + 2).Value)
RgSales.Cells(i + 1, j + 2).Value = newPrice
RgSales.Cells(i, j).Select
Selection.Delete
RgSales.Cells(i, j + 1).Select
Selection.Delete
RgSales.Cells(i, j + 2).Select
Selection.Delete
End If
Next j
Next i
End Sub
我的范围有问题,我只想让它在最后一行数据上结束,在宏运行后删除所有