Filter month

Hello Team,

I’m looking to sort an Excel sheet based on the current month’s dates. Specifically, I have a column containing dates, and I want to filter out all entries from the current month, delete them, and then update the sheet with new data.

Hi @omar_ismail

Try the below linq query:

(From row In dt1.AsEnumerable()
 Where DateTime.ParseExact(row.Field(Of String)("YourDateColumn"), "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MM") <> Now.ToString("MM")
 Select row).CopyToDataTable()

Regards

That would help to delete in the DataTable. I need to filter the Excel to delete in the Excel itself.

Hi @omar_ismail

Can you try the below

Input:

image

Output:

image

Cheers!!

Hi @omar_ismail

Can you provide the sample excel input?

Regards

@omar_ismail

Can you provide the Sample input and output so it is easy to understand

Hi @omar_ismail

Please check the below workflow and the attached xaml’s


Code for invoke vba:

Sub DeleteRowsByCurrentMonth()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim dateColumn As Range
    Dim currentDate As Date
    Dim cell As Range

    ' Set the worksheet
    Set ws = ThisWorkbook.Sheets("Profit") ' Change "Sheet1" to your actual sheet name

    ' Find the last row in the sheet
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    ' Set the date column (assuming it's in column H, change as needed)
    Set dateColumn = ws.Range("H1:H" & lastRow)

    ' Get the current month
    currentDate = Date

    ' Loop through each cell in the date column
    For Each cell In dateColumn
        ' Check if the cell value is a date
        If IsDate(cell.Value) Then
            ' Check if the month of the date is the same as the current month
            If Month(cell.Value) = Month(currentDate) Then
                ' Delete the entire row
                cell.EntireRow.Delete
            End If
        End If
    Next cell
End Sub

Please change the sheet name column’s as per your original data.

Note: The date format is MM/dd/yyyy

I have attached the xamls please check
Main.xaml (16.1 KB)

FOrum.txt (999 Bytes)

Regards

the below column contains two diffrent months so i need to filter with the current month (01) then do delete it
image

HI @omar_ismail

Please check this

Regards

I don’t need to write and need to filter then to delete in the same excel

I found the solution guys

image

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.