Community discussion forum

Inserting text from a cell into VBA code

  • 4 months 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!

    Post was edited on 27/07/2009 17:27:17 Report abuse
  • 4 months 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.

  • 4 months ago

    Excellent, thanks!

Post a reply

Enter your message below

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

We'd love to hear what you think! Submit ideas or give us feedback