Inserting text from a cell into VBA code

vba , excel , office London, United Kingdom
  • 11 years ago

    I have a macro that amongst other things sorts a number of lists by a month, however instead of rewriting the code for every month i want to be able to enter the month into a cell and have the code pick up that month and sort by it. How can I do this?

    For example, my autofilter is: Selection.CurrentRegion.AutoFilter Field:=4, Criteria1:="Jul09"

    But I want to replace the Jul09 with a link to a cell in which i can enter any date in the form "mmmyy" and have the code filter by that date.

    Thanks!

  • 11 years ago

    If your month is in cell F1, you can use code like this:

    Selection.CurrentRegion.AutoFilter Field:=4, Criteria1:=Range("F1").Value

    to select the cell value as the criteria.

  • 11 years ago

    Excellent, thanks!

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“To iterate is human, to recurse divine” - L. Peter Deutsch