VBA EXCEL TO ADD DATA BASED ON A CELL DATA AND DATE DATA

wndncg

Board Regular
Joined
Mar 24, 2017
Messages
84
Office Version
  1. 2019
  2. 2016
  3. 2013
Basically ill need a code to filter out:

Done:
Find data and paste to FIN_sheet Based on cell (A1 from TEMPLATE_sheet)
Query:
Find data and paste to FIN_sheet Based on cell (A1 & Date in C1 from TEMPLATE_sheet)

See image:
TEMPLATE_sheet
1663227260201.png


FIN_sheet
1663227307478.png


Already have the Code for add i just need the additional code for DATE (ADD PER DM):
Sub DATA()

Dim wsData As Worksheet
Dim wsTemp As Worksheet
Dim v As Variant
Dim lr As Long
Dim r As Long

Application.ScreenUpdating = False

' Set worksheet variables
Set wsData = Sheets("TEMPLATE")
Set wsTemp = Sheets("FIN")

' Capture value to filter on
v = wsData.Range("A1")

' First clear range on TEMPLATE_SHEET
' wsTemp.Activate
' Rows("4:" & Rows.Count).Delete

' Find last row on DATA_SHEET
wsData.Activate
lr = Cells(Rows.Count, "B").End(xlUp).Row

' Loop through all rows on DATA_SHEET
For r = 1 To lr
' Check value in column A
If Cells(r, "B") = v Then
' Copy columns B-D to TEMPLATE_SHEET
Range(Cells(r, "A"), Cells(r, "D")).Copy wsTemp.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
End If
Next r
Call ADD_SEQ_01
Application.Wait (Now + TimeValue("00:00:01"))
Call ADD_SEQ_02
Application.ScreenUpdating = True
wsTemp.Activate
MsgBox "ADDED_-WNDNCG"
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Rich (BB code):
Sub DATA()

    Dim wsData As Worksheet
    Dim wsTemp As Worksheet
    Dim v As Variant
    Dim lr As Long
    Dim r As Long

    Application.ScreenUpdating = False

    ' Set worksheet variables
    Set wsData = Sheets("TEMPLATE")
    Set wsTemp = Sheets("FIN")

    ' Capture value to filter on
    v = wsData.Range("A1")
    dd = wsData.Range("C1")
    ' First clear range on TEMPLATE_SHEET
    ' wsTemp.Activate
    ' Rows("4:" & Rows.Count).Delete

    ' Find last row on DATA_SHEET
    wsData.Activate
    lr = Cells(Rows.Count, "B").End(xlUp).Row

    ' Loop through all rows on DATA_SHEET
    For r = 1 To lr
        ' Check value in column A
        If Cells(r, "B") = v And Cells(r, "A") = dd Then
            ' Copy columns B-D to TEMPLATE_SHEET
            Range(Cells(r, "A"), Cells(r, "D")).Copy wsTemp.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
        End If
    Next r
    Call ADD_SEQ_01
    Application.Wait (Now + TimeValue("00:00:01"))
    Call ADD_SEQ_02
    Application.ScreenUpdating = True
    wsTemp.Activate
    MsgBox "ADDED_-WNDNCG"
End Sub
 
Upvote 0
Solution
Rich (BB code):
Sub DATA()

    Dim wsData As Worksheet
    Dim wsTemp As Worksheet
    Dim v As Variant
    Dim lr As Long
    Dim r As Long

    Application.ScreenUpdating = False

    ' Set worksheet variables
    Set wsData = Sheets("TEMPLATE")
    Set wsTemp = Sheets("FIN")

    ' Capture value to filter on
    v = wsData.Range("A1")
    dd = wsData.Range("C1")
    ' First clear range on TEMPLATE_SHEET
    ' wsTemp.Activate
    ' Rows("4:" & Rows.Count).Delete

    ' Find last row on DATA_SHEET
    wsData.Activate
    lr = Cells(Rows.Count, "B").End(xlUp).Row

    ' Loop through all rows on DATA_SHEET
    For r = 1 To lr
        ' Check value in column A
        If Cells(r, "B") = v And Cells(r, "A") = dd Then
            ' Copy columns B-D to TEMPLATE_SHEET
            Range(Cells(r, "A"), Cells(r, "D")).Copy wsTemp.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
        End If
    Next r
    Call ADD_SEQ_01
    Application.Wait (Now + TimeValue("00:00:01"))
    Call ADD_SEQ_02
    Application.ScreenUpdating = True
    wsTemp.Activate
    MsgBox "ADDED_-WNDNCG"
End Sub
worked perfectly ty.
 
Upvote 0
You are welcome
And thank you for the feedback
Be happy and safe
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,617
Latest member
Narendra Babu D

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top