How to loop collect data with month/year condition

oshi1998

New Member
Joined
Jan 13, 2021
Messages
7
Platform
  1. Windows
Hello everyone, Sorry, My English isn't that good. I'm still practicing.
I'm beginner, i need help. :) i need source code this.

Step 1 : Condition for collect is from black box in picture. user will input date here.
Step 2 : Click Button
Step 3 : Collect data with condition and show only data month/year equal and less than condition but still in same year(condition)
example.PNG

Example : If i input condition = "18/03/2021" , Form below will show data like this.

Name Lastname Date Dept ID
Pajaree Intichai 18/01/2021 KK 880593
Kajai Thong 11/03/2021 KK 880081
Em pama 14/03/2021 KK 880955


Help me please. Thank for help. ?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hello , can You please share, whether the black box is simply a cell?
secondly, your raw data is in sheet1 and you want the data to be collected according to your condition from sheet1 and show in sheet2 or different workbook?
 
Upvote 0
Hello , can You please share, whether the black box is simply a cell?
secondly, your raw data is in sheet1 and you want the data to be collected according to your condition from sheet1 and show in sheet2 or different workbook?
Sorry for late reply. Yes sir,it's just a cell.
I want results 2 styles
I would like to study and see that how source code work... 2 styles

style 1 , show in current sheet.
style 2, show in new sheet.


All are in current workbook.
Thank for help. ?
 
Upvote 0
Please give it a try
VBA Code:
Sub mycode()
Dim v As Date
Dim startrow As Byte
Dim lastrow As Byte
Dim i As Byte
Dim j As Byte
j = 4
Application.CutCopyMode = True


startrow = 4
lastrow = Range("c" & Rows.Count).End(xlUp).Row
v = Range("d1").Value
For i = startrow To lastrow
If VBA.Month(v) = VBA.Month(Range("c" & i).Value) Then
    Range("a" & i, "e" & i).Copy
    Range("h" & j).PasteSpecial xlPasteColumnWidths
    Range("h" & j).PasteSpecial xlPasteValuesAndNumberFormats
   
    j = j + 1
End If
Next i
Application.CutCopyMode = False

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,766
Messages
6,126,763
Members
449,336
Latest member
p17tootie

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