VBA Greater Than Date issue with Autofilter on a new workbook

vbanewbie68

Board Regular
Joined
Oct 16, 2021
Messages
171
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi

Everything is working fine, only one thing, when the macro moves the selected data onto a new workbook as per the attached screenshot capture1. This is good so far but the issue is that the autofilter is still visible. When I remove the autofilter it expands the whole data for the 214 records instead of 4 records. My code is as below using Greater Than in VBA. I have tried to use paste special and this doesn’t work. What is the best way to do this?

' Input Greater than

ActiveSheet.Range("A1").AutoFilter Field:=7, Criteria1:=">" & Application.InputBox("Great Than Date"), Operator:=xlAnd

'Move to new workbook

ActiveSheet.Move

Ideally it would be as the attached screenshot capture 2. I run a macro, I get an inputbox to allow me to enter the date using the Greater than. This will select the data and move it to a new workbook. Hope this makes sense?

Your help is much appreciated on this matter.

Thank you

Regards
 

Attachments

  • Capture1.PNG
    Capture1.PNG
    70.2 KB · Views: 13
  • Capture2.PNG
    Capture2.PNG
    113.7 KB · Views: 12
I don't believe the issue is with the code but with the data.
The way it looks to me in the image in Post #7 the Date-Time field is Text (Column G)

To convert Column G to date-time, select the column and
• Ctrl+H then replace "." with "/" without quotes (period with slash)
• Text to Columns > Delimited > Finish

Then try the macro again.

Asssuming that works you then need to address how the data is being populated to address the how to automate the process in the future.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi vbanewbie68,

my last try here, use this shortened codeline:

VBA Code:
lngDate = CDate(varAns)

And to be honest: I would never let any user enter a date via Inputbox/Application.InputBox. By setting Type:=2 for the second one the value returned is a string but that string could hold any value or special character breaking the conversion to Date.

Microsoft had a Date Picker which was taken out of the available controls nearly ten years ago. I would either depend on any third party (free9 DatePicker/calnedarControl or help myself with a small UserForm (3 Comboboxes and 2 CommandButtons) but would have to make sure that Feb. 29, 2023 is not a valid Date (you can restrict that by making the controls available only after year and then month have been chosen).

Holger
Hi Holger

I am pleased to let you know that I have managed to fix the issue with your last code in it. It works successfully. Again thank you so much of your time on this matter. I have learned greatly from your codes and your useful comments too. 😀

Regards
V
 
Upvote 0
I don't believe the issue is with the code but with the data.
The way it looks to me in the image in Post #7 the Date-Time field is Text (Column G)

To convert Column G to date-time, select the column and
• Ctrl+H then replace "." with "/" without quotes (period with slash)
• Text to Columns > Delimited > Finish

Then try the macro again.

Asssuming that works you then need to address how the data is being populated to address the how to automate the process in the future.

Hi

Thanks for this a good advice. I found that your help is interesting and it work in that way. Thanks again.

V
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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