Page 1 of 1

vba copy data base on month

Posted: Thu Oct 22, 2020 12:58 pm
by sna
Hi Dear

I have a problem with copy data from multiple sheets base on current month.for example this month is Oct so if the month is Oct copy row contain that month to Sheet Main.
But my code not working fine


Best wishes

Re: vba copy data base on month

Posted: Sat Oct 24, 2020 12:17 am
by snasui
:D Try this,

Code: Select all

'Other code
For i = lr To 2 Step -1
    On Error Resume Next
    If IsDate(.Range("b" & i).Value) Then
        If Month(.Range("b" & i).Value) = Month(Date) And Year(.Range("b" & i).Value) = Year(Date) Then
            .Range("b" & i & ":g" & i).Copy Destination:=sh.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
             sh.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Value = .Name
             sh.Columns("f:f").EntireColumn.Hidden = True
        End If
    End If
    On Error GoTo 0
Next i
'Other code

Re: vba copy data base on month

Posted: Sat Oct 24, 2020 1:54 pm
by sna
🙏