My excel file has a column for customer name (there are more columns btw). I have the filter feature on. The customer list is in column F.
I recorded a macro by copying a customer (from the customer column, say from cell F99). Then I click on the filter arrow and select the 'custom' option and in the dialog box that comes up, I paste the copied customer and try to find other records which have the same customer name.
This works great but when I run the macro for some other customer, say from cell F200, the pasting part, pastes the customer that I had selected when recording the macro.
Is there a solution to make this generic so that the macro will work in a manner that I simply highlight the cell of the desired customer and then then run the macro which will give me the result.
I have one master sheet of data, with a large number of fields and data.
I need to turn this master data into individual records, each record exisiting as an individual worksheet - lets call it a 'U'. The U is a template sheet which has calculations and lookups built into it to complete further information. The completed U's are then used by a number of people for different reasons. There are 3 main 'flavours' of these sheets which have slightly different uses.
I've gone from knowing nothing about macros to having learned enough about them in the last week or so to populate each individual sheet with the data, and save the new file in the location I want it to go.
What I want to do now is filter the fields displayed by the individual U sheets, as not every field is applicable to each 'flavour'. I've marked up the rows as to the appropriate flavour - e.g. Row 17 is applicable to 'P' 'F' and 'R' ( Cell which is auto filtered contains PFR), but Row 18 is only 'P' and 'F' (Cell contains PF).
I've gone through the master file and identified each entry as a the appropriate flavour - to summarise what I'd like to do now:
1) Automatically populate the template file with the relevant data. (which my macro will do) 2) Use an autofilter to filter the rows equal to the data in the reference sheet so these are the only ones displayed. Eg. Reference sheet says 'P', so I want to filter the U sheet where autofilter column contains the letter 'P' 3) Rename the file and save as my reference in the location I want it to (which the macro is doing).
(where CF3 = the cell in the master data with the flavour in it, "USS iss1" is the template U file, G158 is a spare cell and Autofilter Field 1 contains the row reference which tells me which data applies to which flavours).
I've tried using the macro recorder, which when I paste the value in the autofilter/contains box records it as the value I've just put in rather than a copy of the reference cell. I've tried
and other variations on the same theme, but to no avail - I get "Compile error: Expected:expression".
Explanation This has been my Autofilter criteria to date Criteria1 = " " (needed for other macros) Criteria2 = "=2007*" (i.e. starts with JobYear)
This works fine but now I am wanting Criteria2 to be linked to a cell where the user will enter the job year to be filtered.
Solution My guess at solutions would be: Criteria1 = " " Criteria2 = Cell* or Criteria2 = Cell & "*"
Unfortunatley I have been unable to find any way of making this happen. Using an Autofilter to link to a cell is standard but making an Autofilter link to a cell with a starts with criteria attached doesn't seem to be doable.
I'm trying to add to my code an autofiler with multiple criteria, the criteria is held in single cell. The criteria is made up of anything from 5 to 30 cells, then i have tried to concatenate these separated by commas, in speech marks, speech marks and commas etc., set them as an array the use that in my filter, but nothing seems to work.
I have a chart that gets updated to show the desired reporting period by clicking a button to run some code which applies filtering to the source worksheet using a value selected from a drop down validation list on the chart worksheet. When the code runs, the source worksheet displays temporarily. How do I prevent this switching back and forth between the data and chart worksheets during code execution? Undoubtedly, there is a better way to code this.
Sub Chart_FilterPPM() Application.DisplayAlerts = False wk = Worksheets("Charts"). Range("D63") Worksheets("Leak Data").Activate With Worksheets("Leak Data") .AutoFilterMode = False .Range("Headings_LeakData").AutoFilter End With With Range("Headings_LeakData").AutoFilter Selection.AutoFilter Field:=2, Criteria1:=wk Selection.AutoFilter Field:=11, Criteria1:=">5000", Operator:=xlAnd End With Worksheets("Charts").Activate Application.DisplayAlerts = False End Sub
Thats the best I could describe that What I face today is the means to run a VBA Autofilter from an Activecell. The Activecell is a search result. I have a table that spans from A1 to E5000. The Activecell will always be in Column A. What I need to happen in when the Activecell is found an Autofilter is placed in the block of data from Column B to E. The rows will change after every search hence my dilemma. Each block of data has its own header as well
So if my Activecell is A2 then I need B1:E4 Autofiltered then Column E sorted Smallest value to Largest. The Activecell needs to remain static. The size of the blocks of data are exactly the same.
Here is a photo example of the desired result. Untitled.jpg
I am trying to make an "intelligent" auto filter that with filter with increasing restriction until a certain criteria is met.
The list runs from A5:G20. In coloumn G is the number of hours associated with each event. And in A1 I have the percentage of items showing/whole list so it I have 15 rows on the list, and I filter so that only 5 are showing, cell a1=33%
How can I make a macro that will autofilter until the the a1=5% Like having filter criter = equal or greater then 1 hour, if a1 > 5% Then criteria + 1 hour If A1=<5%, then stop.
basically a seed criteria of 1 hour, adding 1 hour until the value in a1 = 5%
I can select the top cell in column "F" after filtering by multiple columns using VBA and arrays, but now want to I want to use the top cell in column "F" to search for all other equipment that uses this item.
E.g. remove filter, and reapply autofilter to column "F" based on selected cell as per below VBA
Note: Row 1 contains command buttons and row 2 Headers.
whenever the active cell is within a given range, highlight the cell on the same row in column S (by changing its interior colour). This should occur each time the active cell is changed, whether by cursor keys or mouse. The effect would be similar to the row and column highlights at left and top of the worksheet.
This action should be restricted to one sheet in the workbook.
I have got stuck on one piece of my code and having trouble fixing... Overall I am trying to find variable station name in cell L2 of Sheet 2 in Sheet 1 and then select and copy the data from the data in "cell L2 of Sheet 2" to the last entry of that row. I have attached an example test spreadsheet of the data and a macro is within Sheet 1 called test1. Please note that cell L2 in Sheet 2 will always be different station name and the station list in Sheet 1 will change with differing station name.
The code I am using is:
The code that is not working and bringing up an error is:
My problem is following: I have a list of data that are classified according to a particular character, and I want to copy (with auto filter through the macro) the relevant information to the appropriate place in the sheet where it belongs. That's no problem. The problem is that if I want to copy data, classified by a character that is not listed in the table (that is not in the filtering criteria), then all the data are copied to the appropriate place. But I do not want to copy in this case nothing. How should such a macro look like?
I have some data which I want to apply multiple criteria to for a particular column. Searched around on the internet and it would appear I should use an array and pass that to my criteria. What I can't find an answer for is how to say "does not equal any of the values within the array"
Code currently is:
Code: Dim NumberFilter_Array(0 to 2) NumberFilter_Array(0) = 2 NumberFilter_Array(1) = 9
I've tried variations for that in red but can't get it to work, how to correct the line in red to filter for none of the values in the array NumberFilter_Array?
I am trying to use VBA to set an autofilter that hides all zeros in Column AL and then excludes all values in Column E that start with "312" or "502". For some reason I can't get this to work as expected, it still continues to display unwanted values in Column E.
I'm actually trying to write a Macro that applies autofilters and the information just doesn't show! The autofilter is properly applied and everything, but the only visible row is the header. The code is the following.
I would like to do some search function. As I know, to have "contains" in criteria, I can simply add *. But then, the asterisk(*) doesnt work with forms. I want my user to put the word they are looking for in a form then the system will select from a different worksheet. Below is my coding and bold is my biggest problem.
I want to write a VBA routine to compare the Autofilter criteria found on two different worksheets. If the criteria is not the same I will display an error message. The range the Autofilter is working on could be one to many columns. The criteria could be anything from selecting a value from the autofilter list to multiple columns using a custom autofilter with multiple conditions.
I'm trying to make the criteria in an autofilter bit of code be the value of a cell in my spreadhseet. I have named the cell and would like to reference the named range rather than the cell address if possible.
I have the following code based on Multiple user-selected dropdowns. What I need to add is I believe a Volatile Application, where if the user chooses the option "ALL" OR leaves blank (doesn't pick anything from the dropdown,) the respective column does not get Autofilter applied. I have 6 different criteria, including a Start Date and End Date. So, the final result I'm trying to get is to have autofilter applied to only those columns for which the user selected a specific option.
Dim dDate As Date Dim strDate As String Dim lDate As Long Dim rDate As Range
Worksheets("Data").AutoFilterMode = False Set rDate = Sheets("Summary").Range("B3")
If Not IsDate(rDate) Then 'Check if valid MsgBox "Non valid date and time" Exit Sub End If
And this criteria can be changed by the user anytime. Now for some reason sometimes I trigger a code which works under Function key(F8) and it refresh some data from the database. Just before it gets the data, it will remove the filter such as :
I have a Excel-spreadsheet (sheet1) which has dates in column G. I am looking for autofiltering data by year or month based on date value in column G. In my userform I have two comboboxes, one has years from 2009-2014 and another one are months from Jan-Dec. How can I write a code that shows only rows which match either year or month value based on combobox selection?