VBA EXCEL filtering with Or criteria with 2 different rows - vba

I want to filter with 2 criteria with "Or" relationship between the two criteria. However, the 2 criteria are on 2 different rows. I want to filter the first row for number for 6 to 7 or the second row for the date of 2010/6/16 and 2010/7/1. How could I code for the filtering?
My 2 columns

Related

Using VBA to create a grid from 3 spreadsheets with the row, column, and values

I have three excel spreadsheets. The first has the values that are to be assigned to a new excel spreadsheet. The second has the column that the data belongs in. The third has the row that the data belongs in.
It looks something like this:
Data Value:
1 5 7 9
2 2 6 8
Column Number:
1 2 3 1
2 3 1 2
Row Number:
1 2 3 2
4 4 3 1
How can I combine all of this information to create a single spreadsheet that contains the values in a format like this:
Column
1 2 3
Row
1 1 8 0
2 9 5 0
3 6 0 7
4 0 2 2
I have tried to do it by using loops in vba, but I am a beginner and I am having some difficulty.
I know that I need to use a loop that checks the row and column that the data is supposed to be in against the row and column for each iteration. I am just not sure how to go about doing that.
Assuming these are different sheets in the same workbook (if not - create a new workbook and copy the sheets over). I assume that on each sheet, the same range of cells is used (for example A1:D2 in all 3 cases with the values on the first sheet, the column numbers in the second and the row numbers in the third). You can dispense with VBA entirely at the expense of using some complicate formulas (inspired by this excellent article: http://exceluser.com/blog/1043/how-to-create-two-dimensional-lookups-in-excel-formulas.html )
Step 1. Add a fourth sheet and in A1 add the formula
=CONCATENATE(Sheet3!A1,"_",Sheet2!A1)
and copy it over the appropriate range (e.g. A1:D2). This will give you things like 2_1 which tell you that the corresponding entry in sheet 1 belongs in row 2 column 1. Name this range "location" (formula tab - define names option)
Step 2 - Decide where you want to hold the data (I'm assuming it is in sheet 4 for simplicity) And add the row numbers (1-4) and the column numbers (1-3) as labels. In my case the row labels are in A5:A8 and the column labels in B4:C4 (see the screenshot below). Then in the upper left corner of the values to be filled in (B5 in my case) enter the following formula (suitably adjusted to match your ranges):
=IFERROR(INDIRECT(ADDRESS(SUMPRODUCT(ROW(location)*(location = CONCATENATE($A5, "_",B$4))),SUMPRODUCT(COLUMN(location)*(location = CONCATENATE($A5, "_",B$4))),,,"Sheet1")),0)
and copy it over the intended range. Be careful with the dollar signs - this formula mixes row absolute and column absolute references in an essential way. Somewhat oddly, it actually works:

How to compare a list of rows to another list of rows in Excel?

I am trying to figure out if there are any differences between a list of data with another. In order for a row of data to "match" with another row, the row must have the same values in their corresponding column. The rows themselves do not have to be in any particular order. In particular, I am dealing with a parts list, where there are part numbers, descriptions, etc. I am trying to figure out if any rows of data are different from rows of data from another list.
I found Compare two sheets using arrays, which may have the answer to my problem, but I am having trouble figuring out how to adapt to my code due to inexperience in Visual Basic.
I was able to get it to work for a single column of data, comparing one column of data from one sheet to another, but cannot get it to compare entire rows of data.
Here is an example of I want this to work:
Sheet 1 Sheet 2
Column 1 Column 2 Column 1 Column 2
Row 1 22a 33 11 11
Row 2 22a 33a 22a 33
Row 3 55 22b 55 23b
The code in the link will tell you what is not in sheet 1 but in sheet 2 and vice versa. In this example, I would like the code to tell me Sheet 1 Row 2 and Sheet 1 Row 3 are not in Sheet 2, and Sheet 2 Row 1 and Sheet 2 Row 3 are not in Sheet 1 (Sheet 1 Row 1 and Sheet 2 Row 2 match).
If that is ok by you, you can do it without VBA using the following formula:
={IF(IFERROR(MATCH(A1&"|"&B1;Sheet7!$A$1:$A$3&"|"&Sheet7!$B$1:$B$3;0);-1)=-1;"Unique";"")}
Assuming that each of your tables start in A1 (so that the tables with three entries span A1:B3), and entering this formula into C1 (and copying it down), press CTRL+SHIFT+ENTER when entering the formula to create an array formula, this will show the word "Unique" in column C if the pair in that row on that sheet is not in any of the row-pairs on sheet 2.
You can then use conditional formatting to highlight unique rows, filter on the tables to include only unique rows, or some other way of doing what you need.
NOTE 1: I have entered my numbers in Sheet6 and Sheet7 instead of 1 and 2. The formula written above goes into Sheet6.
NOTE 2: My language use ; instead of , as function separator, so if yours use , you need to change that.
NOTE 3: You will need to expand the ranges Sheet7!$A$1:$A$3 and Sheet7!$B$1:$B$3 if your set grows (this will happen automatically if new rows are inserted in between the old ones). The best is still probably to create named ranges for each of the 4 columns, exchange the references with those, and manage the named ranges instead of the formulas.
NOTE 4: If your data set contains the character "|", you need to change that as well, to match some character that you for sure do not have there.
Alternatively you could in column C on each cheet enter (assuming first entry in C1)
=A1&"|"&B1"
and copy this down, then run the solution from your copied example using that C column instead of on A1 and B1.

Apply Count formula in a Excel Row with conditions True/False

I have to apply a logical count formula on a column which contains some value. It contains identical and non-identical numbers.
What I want is a way to apply a formula to the next column which will lookup the whole column and decide on below condition:
whether A1=A2; if True, if A1=A3 and so on till it returns False (not equal value) then count all the true results in a row and reflect the value against the first cell.
Then if there was three match then it should reflect 3 against the first cell and the next two cells should be left blank. Below is the example column:
Numbers No of Days
47.76
-429.98
-429.98
-429.98
-1328.98
-1328.98
-1328.98
-833.32
-643.7
-1328.98
-580.26
-556.76
-556.76
-1181.78
-1139.99
-1124.49
-1103.59
-1103.59
-1091.39
-1048.94
-1048.94
-451.38
-451.38
-321
-321
438.5
477.5
698.76
795.93
795.93
804.83
What I want should be like below after formula:
Numbers No of Days
47.76 1
-429.98 3
-429.98
-429.98
-1328.98 3
-1328.98
-1328.98
-833.32 1
-643.7 1
-1328.98 1
-580.26 1
-556.76 2
-556.76
-1181.78 1
-1139.99 1
-1124.49 1
-1103.59 2
-1103.59
-1091.39 1
-1048.94 2
-1048.94
-451.38 2
-451.38
-321 2
-321
438.5 1
477.5 1
698.76 1
795.93 2
795.93
804.83 1
Please help guys as whatever I tried has failed here. Need some excel experts to share some advise or a resolve.
In Cell B2 use =IF(A2=A1,"",MATCH(0,--(A2=$A2:$A$50),0)-1) entered using ctrl+shift+enter
The if statement checks to see if the number is the same as the one above it and if it is it leaves the cell blank.
Inside the match statement --(A2=$A2:$A$50) returns an array of 0s (if the cell doesn't match A2) or 1s (if it does match). The match statement finds the first 0 in the array (the first number that doesn't match). Since this returns the place in the array that starts at the current row it will give the number of rows that match+1. We just need to subtract that 1 to get the number we need.

Excel consolidate duplicate rows by summing the values

I have an excel spreadsheet with two columns.
CON ITE
TAT 5
T 6
TAG 7
GAT 3
T 8
GAT 2
TAG 6
TAT 3
I would like to remove the duplicates in first column (CON) by summing the values in the second column corresponding to the repeating rows. Im using Excel consolidate to get the work done but Excel consolidates data in this manner
CON ITE
TAT 5
6
7
3
8
2
6
3
Is there any way to properly consolidate this data
Adding as an answer so that I can show results.
Not sure if versions will have an impact, but I am using 2007 and it worked, seemingly fine. Using your data, here are my "Consolidate" results:
CON
TAT 8
T 14
TAG 13
GAT 5
Did you select "Use Labels In Left Column"?
Are you looking for something different?
Did you set up your table as a range, or use the "Format As Table" function?

selective transposing in excel using VB

I am creating an Excel worksheet using VB for a large chunk of data, currently represented by ~ 9500 rows of data in just one column (A1). Each logical record is actually 20 rows of the data.
What I need is:
Select 20 rows of data.
Copy that selection, then TRANSPOSE onto row one, starting at A1 and going through T1.
Then Delete the rows of data that were transposed into row 1 columns (basically delete 20 rows)
Then select the NEXT 20 rows of data, and repeat the whole process, but this time pasting into row 2 instead of row 1 (A2:T2).
This needs to iterate through the whole worksheet until it cycles through all 9500 rows.
The end result will be 475 rows of data, with values in the first 20 columns.