selective transposing in excel using VB - vb.net

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.

Related

VBA: Is there a way to apply a single formula to a column without looping through each cell

I'm quite new in VBA and was looking for ways on how to apply the same formula to all cells in a column. I have 5000 rows and I would simply like to multiply row values in Column 1 with row values in Column 2 and show the results of the same row in Column 3.
I have tried looping through each of the cells:
For i = 1 to 5000
Next i
but the calculation was slow and was wondering if there is another way to calculate all 5000 rows quicker.
I actually have 60 columns with different formulas and conditional statements which slows down the calculation process. I am actually looking for a simpler way to 'BULK' apply a certain formula to the whole column.
The following code makes Column1*Column2=Column3 using Formula property of Range object without a looping
Sheet1.Range("C1:C5000").Formula = "=RC[-2]*RC[-1]"

Excel VBA - Looping to count cell values larger than / smaller than specific value

I'm currently working with a large amount of contract lists. Each list is in a separate worksheet for each year's quarter and it needs to stay that way. E.g.: 2007_Quarter1, 2007_Quarter2, etc. I have 10 years of data, so 40 quarter report worksheets.
Now I need to code a vba routine that would do the following, in the specified order:
In each quarter report worksheet, run through the column containing contract values; then
Count all values between 0 and 10,000; then
Count all values between 10,001 and 25,000; and so on
Then, when there are no more contract values in the range (which will vary from sheet to sheet), go to the next worksheet and repeat the procedure.
All results should be returned in a worksheet (let's call it Worksheets("Report")) in a table where rows are for value intervals (e.g. 0 to $10,000) and columns are for quarters (e.g. 2007 Q1, 2007 Q2, etc.).
One particular aspect of my problem is that, for practical reasons, I'd prefer to set the control intervals' min and max values in a table contained in another worksheet ("Variables"), where, for example, I'd have all minimum values in range C4 down and all maximum values in range D4 down.
For each contract value, an "If" condition should look like:
If ContractVal > Worksheets("Variables").Range("C4").Value And
If ContractVal < Worksheets("Variables").Range("D4").Value Then ...
So far I'm having no success at coding this efficiently. I suspect some loop would work but I can't find a way to make it happen. A loop would do:
In 2007_Quarter1 ws:
For each cell from A4 down to the end, count values included between Range("C4").Value and Range("D4").Value
Then for each cell from A4 down to the end, count values included between Range("C5").Value and Range("D5").Value
... and so on, then repeat for 2007_Quarter2, 2007_Quarter3, and so on.
I need rescue! Thanks in advance!
If it is ok to you to prepare the resulting matrix manually (intervals in rows and quarters in columns) you could write a macro that read the right file and count the contracts in the right range for every cell in the matrix.
If you want to build the matrix automatically you should tell the macro the year range. Then you can write a loop that read the ranges and for every range you write a loop to read every file in the right order.

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.

How to parse multiple rows with concatenated data into a single column

I have an excel spreadsheet with delimited information (tracking #s) in various rows:
row a 630521*630621*630215*610517
row b 630522*630611
row c 630531*630651*630265
row d 630524
I would like to organize all rows of tracking #s, separated by a "*", into one column. Can you tell me how this is possible? I have 4,000+ rows like this with up to 21 tracking #s (variable) in each row that I want to convert to one column with multiple rows.
col a
630521
630621
630215
610517
630522
630611
630531
630651
630265
630524
You can do it all in Excel:
Highlight your column
On the Data menu, select Text to Columns => Delimited => Next => Other * => Finish
Then Copy/Paste each of the resultant columns into a single column and sort it to put the blanks at the bottom.
To save step 3. in Ron Smith's answer where you have a LOT of rows, you might add a blank row at the top and on the left, select you entire range (including all the blanks), apply the technique detailed here, delete the columns labelled Row and Column then filter to delete blank rows from column labelled Value.

Get the max value of un-hidden cells

I have a table that has 20 rows and the table un-hides the amount of rows specified in the cell above my table. so if I put in 5 into the cell, 5 of the 20 rows will be un-hidden.
So now I would like to get the MAX of the say 5 cells that are now unhidden. How would I do this?
=SUBTOTAL(104,RANGE)
104 will give you the max of the unhidden cells. If you replace 104 with 4 it will operate as the normal MAX function UNLESS you are filtering the rows using the built in Excel table function.
Perhaps
=SUBTOTAL(104,your_range)