titicola
Reaction score
404

Profile posts Latest activity Postings About

  • Sub ChiaTheoNgayThang()
    Dim ws As Worksheet
    Dim newWs As Worksheet
    Dim lastRow As Long
    Dim cell As Range
    Dim currentDate As Date
    ' Đặt tên sheet gốc ở đây
    Set ws = ThisWorkbook.Sheets("Sheet1")

    ' Lấy dòng cuối cùng trong cột ngày tháng (giả sử cột A là cột ngày tháng)
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    titicola
    titicola
    ' Khởi đầu giá trị ngày tháng đầu tiên
    currentDate = ws.Cells(2, 1).Value

    ' Khởi tạo dòng đầu tiên của vùng dữ liệu
    Set rng = ws.Rows(1)

    ' Duyệt qua dòng từ 2 đến lastRow
    For Each cell In ws.Range("A2:A" & lastRow)
    ' Nếu giá trị ngày tháng khác với currentDate
    If cell.Value <> currentDate Then
    ' Tạo sheet mới với tên là ngày tháng và đặt
    titicola
    titicola
    currentDate mới
    Set newWs = Sheets.Add(After:=Sheets(Sheets.Count))
    newWs.Name = Format(cell.Value, "ddmmyyyy")
    currentDate = cell.Value
    ' Copy dòng đầu tiên của vùng dữ liệu vào sheet mới
    rng.Copy newWs.Cells(1, 1)
    End If
    titicola
    titicola
    ' Copy dòng hiện tại vào sheet mới
    cell.EntireRow.Copy newWs.Cells(newWs.Cells(Rows.Count, "A").End(xlUp).Row + 1, 1)
    Next cell
    End Sub
  • Loading…
  • Loading…
  • Loading…
Back
Top