I want to create an excel file with 3 sheets.
Sheet 1: Overview
Sheet 2: Products 1, which has 2 columns: Product and amount
Sheet 3: Products 2, which has 2 columns: Product and amount
The idea is that when I enter an amount (e.g. row 2, value 3), it will show up on sheet 1 (Overview). And it will be removed from sheet 1 when the amount is 0.
So I now added links of sheet 2 and sheet 3 on sheet 1.
On sheet 1 I use the Calculate event, so every time the formula changes it fires an event.
In this event I used a for / next loop (1 row till last row), which works fine if you do not have that much products on sheet 1.
But if you have about 150 products it takes about 3 seconds, which is too long.
Is there a way to determine which cell has been changed on sheet 1?
Or is there another way to do this....
Related
I am trying to insert a specific number of blank rows, which is based on a value in a cell. This value in the cell is a count function from a table.
I have an "Import Table" sheet which contains all my data. Next to the table I have a couple count functions, which count general categories coming from the table. For example on the "Import Table" worksheet Cell J8(Domestic Equity), Cell J9 has the count function which for this case comes to "11". I now want 11 rows to be inserted at a specific spot in my "Analysis" worksheet. In this worksheet there are heading also names like the count headings(domestic equity).
So under domestic equity I want the rows to be insert. In the analysis sheet a function is already created in the first row under domestic equity, so the new blank rows have to be inserted under that value in this case under row 6.
The formula already existing in cells (A6,B6,C6,D6,E6) then have to be flash filled into the newly created white rows.
I attached 2 images to hopefully clear up my questions.
Thanks!
Range("A1").Resize(11, 1).Insert (xlShiftDown)
OR
Rows(1).Resize(11, 1).Insert (xlShiftDown)
I have been trying to write a for each loop to go through each row in in one sheet (sheet 2) to remove duplicates in another sheet (sheet 1). I have had no luck researching either.
In sheet 1, I have a list of customer numbers in column B with the type of product they purchased in column c and the cost of that product in column d. In another sheet 2, I have a list of customers in column a and list of products in column b.
I have been trying to write a for each loop to go through each row in sheet 2 to check the customer number and product, find all the duplicates in sheet 1 with the same customer number and product, and deleting the row with the higher balance.
Sheet 1
A(Year) B(Customer #) C(Product Type) D(Cost)
1) 2015 100 A 1
2) 2015 100 A 2
Sheet 2
A(Customer #) B(Product Type)
1) 100 A
For example, if sheet 2 had 100 in column a and A in column b, it would delete row 2.
You could try using the remove duplicates option within excel, would that solve your problem? Or is Sheet 2 update to remove certain customer orders that you would also like to remove.
Edit: To expand on this. Take the list, sort it by customer and cost (low to high). Then if you click remove duplicates, you'll have the option to select what columns to use as a basis for removing duplicates, so obviously remove cost, and then it'll clear out all but the topmost row, which as now been sorted to be the lowest value.
I have a macro that increase a cell by 1 on the active sheet but I need to change the code to increase a number on a different sheet without selecting the sheet that I want to increase the number on
Example: I have 5 sheets that are the same and run the same macro and the 6th sheet I have has a invoice number that I need to increase by 1 without selecting it
Here's the code I'm using now
Range("X1").Value = Range("X1").Value + 1
I've tried
Sheets("sheet6").Range("O2").Value = Range("O2").Value + 1
but it just make the cell value 1
If the cell has nothing or zero, it will put 1 in the cell. If the cell has a number, it will put the number + 1. If the cell has a text, it will bring an error.
Beware that typing Range("O2") will take the range from the sheet where the code is. It's not necessarily "sheet 6". (So if in that sheet the value is empty, it will result in 1)
Use Sheets("sheet6") on both sides of the assignment.
Sheets("sheet6").Range("O2").Value = Sheets("sheet6").Range("O2").Value + 1
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:
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.