ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   macro Lookup (https://www.excelbanter.com/excel-worksheet-functions/246283-macro-lookup.html)

DamienO

macro Lookup
 
Hello,
I've set up a macro to filter a list using a week number. Obviously the week
number changes. When i run the macro I have at the moment it keeps the
original week number e.g. 44, every time it runs. I set it up so that you
should be able to put the week number into cell "f2" and then the macro uses
the value to filter the list by.
What have I done wrong?

Bob Phillips[_3_]

macro Lookup
 
Hard to tell without seeing any code.

--
__________________________________
HTH

Bob

"DamienO" wrote in message
...
Hello,
I've set up a macro to filter a list using a week number. Obviously the
week
number changes. When i run the macro I have at the moment it keeps the
original week number e.g. 44, every time it runs. I set it up so that you
should be able to put the week number into cell "f2" and then the macro
uses
the value to filter the list by.
What have I done wrong?




Gary''s Student

macro Lookup
 
In VBA, AutoFilter likes strings:

Sub Macro1()
Dim s As String, r As Range
s = Range("F2").Value
Set r = Range("G5:I22")
r.AutoFilter Field:=1, Criteria1:=s
End Sub

where G5 thru I22 contains:

alpha beta gamma
40 6 6
42 7 7
43 8 8
42 9 9
41 10 10
40 11 11
45 12 12
50 13 13
46 14 14
41 15 15
44 16 16
41 17 17
44 18 18
43 19 19
43 20 20
49 21 21
49 22 22

--
Gary''s Student - gsnu200908


"DamienO" wrote:

Hello,
I've set up a macro to filter a list using a week number. Obviously the week
number changes. When i run the macro I have at the moment it keeps the
original week number e.g. 44, every time it runs. I set it up so that you
should be able to put the week number into cell "f2" and then the macro uses
the value to filter the list by.
What have I done wrong?


DamienO

macro Lookup
 
HI,
That works for me after a little change on the sheet.
Thanks for the help

"Gary''s Student" wrote:

In VBA, AutoFilter likes strings:

Sub Macro1()
Dim s As String, r As Range
s = Range("F2").Value
Set r = Range("G5:I22")
r.AutoFilter Field:=1, Criteria1:=s
End Sub

where G5 thru I22 contains:

alpha beta gamma
40 6 6
42 7 7
43 8 8
42 9 9
41 10 10
40 11 11
45 12 12
50 13 13
46 14 14
41 15 15
44 16 16
41 17 17
44 18 18
43 19 19
43 20 20
49 21 21
49 22 22

--
Gary''s Student - gsnu200908


"DamienO" wrote:

Hello,
I've set up a macro to filter a list using a week number. Obviously the week
number changes. When i run the macro I have at the moment it keeps the
original week number e.g. 44, every time it runs. I set it up so that you
should be able to put the week number into cell "f2" and then the macro uses
the value to filter the list by.
What have I done wrong?



All times are GMT +1. The time now is 02:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com