in excel, running from vb.net, can I add the values of all the cells in one sheet to the cells in a different sheet? - vb.net

I have a vb.net application that uses excel. One of the things it does is total the cells in a certain by a certain type, which for the purposes of this question is not relevant. The result is that the cells in sheeta are added to sheetb. This is a repetitive process as multiple copies of sheeta are processed and i want the total of 'all' of the sheeta cells to be added into sheetb. If there were 50 copies of sheeta, then the value of cell A3 in sheetb, for example, would be the total of the values in cell A3 of the sheetA. I am doing it as a cludge now by adding the value of each cell individually. I'd like to be able to use all of the cells in a few statements only, without doing addition statements repetitively.
Thanks for the help

You have a couple of options:
You can write code to cycle through the sheets to build a SUM formula in sheetb for each of the instances of sheeta
You can consider using a PivotTable that draws from multiple sources. Then you simply need to refresh the PivotTable whenever data changes in any of the source sheets. You can refer to this Microsoft Support Page for instruction on how to build it: https://support.office.com/en-ca/article/Consolidate-multiple-worksheets-into-one-PivotTable-report-3ae257d2-ca94-49ff-a481-e9fc8adeeeb5
In either case, you will need to be weary that if you add additional instances of sheeta (or remove them), then you will need to rebuild the formula in option 1 or the PivotTable in option 2.

Related

Conditional formatting 1 cell based on cell input on another sheet, apply to entire row

For work I need to create a resource management excel file. My goal is to create an overview as is seen here:
If John would have taken a few hours off, or if he has a fey hours of sick leave, I would like to turn this cell only to change colour so I know that John will be absent for whatever reason on this day.
However, since I'm creating this for an entire row (for a whole year), I do not want to create conditional formatting per cell because that would be plain madness.
Here is an example per employee (in this example John):
enter image description here
So what I need is a formula to check if a cell in a row (for example sick leave) on the employee worksheet is grater than 0 and then change the colour of only the corresponding cell on the recourse planning worksheet, not the entire row.
Does any of you guys know if this is possible in excel 2016? Preferably without VBA scripting since I have to transfer this excel file to a co-worker who is not into VBA programming.
Thank in advance.
Nuntius transmittendus!
This is definitely possible without any code. Use CountIf() as tinus087 commented. The tricky part is how to create the address range used by the CountIf() so that you can put one conditional format on all the cells. On the the one hand you need the column of the cells being checked to match the column of your total cell. On the other hand the worksheet tab name needs to change depending on which row you are on. So use INDIRECT() to point to the correct worksheet and OFFSET() to look at the correct cells.
So, for cell C4, the formula you want to use as the range in your CountIf() is OFFSET(INDIRECT($A4&"!A1"),3,COLUMN(C1)-1,4). When applied to cell C4 this creates address John!C4:C7. When used for cell D4, it results in John!D4:D7.
You'll probably want some error checking to deal with the #REF! error happens when the formula is applied to a row without a first name or where the name listed doesn't match any worksheet tabs.
Something else to think about, if you haven't already, what happens if there are two John's? Is the 2nd John going to be named John2?

Need VBA script to extend Excel table every week

The problem is as follows: I have several tables in Excel with given number of raws and dynamic number of columns (each week a new column should be added, currently I'm doing it manually). I want to automate it and create a script that will extend every raw range to the next column (namely the range from A2 to C2 should become from A2 to D2), and so on (such that running script N times will result in extending a table to N columns further). By "extending" I mean extending formulas, since each cell in my tables contains any formula. Is there any way to do it via VBA?
I can't just record the corresponding macro because I have now idea how to specify that I don't want to link it with any specific range, but instead always extend just to one column right.
Any help and examples will be very appreciative.
You dont need VBA to do this. Use dynamic defined names and reference them in your formulas. For example, if you add a named range and add this in the refersTo dialog
=OFFSET($A$1,0,0,COUNTA($A:$A),COUNTA($1:$1)
your range will automatically expand from cell A1 (as long as there are no blank cells in column A or Row 1). You can then use that named range in your formulae.
More here http://www.excel-easy.com/examples/dynamic-named-range.html

Workaround for either my approach or the 256 character limit in Excel VBA

My problem is as follows, I have a workbook with (to begin with) 2 worksheets, the first (called WIP) acts as a form of data entry, each new occurrence of the BoM requires an insertion of 4 columns which happens to the left of the existing columns. At the same time a new worksheet is created based on a copy of the existing second worksheet (called FitOut) which pulls various bits of a data from the first worksheet based mainly upon the version of the BoM selected and the supplier referenced.
Of course adding new columns to the WIP sheet causes the functions, arrays and formulas in the sheets to automatically update, I had used a quick workaround by using some code to hold and then paste the new occurrences data into the worksheet which is created at the start of the macro, however the formulas have become slightly complex (due to the need to look for the previous 4 occurrences and return values based on specific cell locations) that the 256 character limit has been completely shot ( I think I'm over 800 on some bits).
I've very limited as to the layout of the WIP sheet, and the sheet needs to be fairly idiot proof (hence macros, buttons etc) but it needs to run well...
ANy and all suggestions/help would be much appreciated.
I have put an example of the formula I am trying to use, if it can be condensed further pleas let me know:
=IFERROR(IF($C$1='WIP'!$U$1,(INDEX('WIP'!$A$1:$X$2500,SMALL(IF('WIP'!$U$1:$U$2500=$A$1,ROW('WIP'!$U$1:$U$2500)),ROW(6:6)),COLUMN('WIP'!$C:$C))),(IF($C$1='WIP'!$X$1,(INDEX('WIP'!$A$1:$AA$2500,SMALL(IF('WIP'!$X$1:$X$2500=$A$1,ROW('WIP'!$X$1:$X$2500)),ROW(6:6)),COLUMN('WIP'!$C:$C))),(IF($C$1='WIP'!$AA$1,(INDEX('WIP'!$A$1:$AD$2500,SMALL(IF('WIP'!$AA$1:$AA$2500=$A$1,ROW('WIP'!$AA$1:$AA$2500)),ROW(6:6)),COLUMN('WIP'!$C:$C))),(INDEX('WIP'!$A$1:$AG$2500,SMALL(IF('WIP'!$AD$1:$AD$2500=$A$1,ROW('WIP'!$AD$1:$AD$2500)),ROW(7:7)),COLUMN('WIP'!$C:$C)))))))),"")

Copying a worksheet in Excel 2013 using VBA to the end of the workbook

I am working in Excel 2013 and am having some trouble. I have researched online all day and can't seem to find anything that solves my problem.
I have an Excel document that consists of 6 sheets:
Format
Summary
1.1 Detail
1.2 Detail
1.3 Detail
1.4 Detail
The 'detail' sheets are formatted all the same. The 'Summary' sheet rolls up all the values from the 'details' sheets and has all kinds of charts and useful information in it. The 'format' sheet is what I created to try to make this document more dynamic and useful for all different kinds of projects. This document is being used for estimating projects, so different projects are going to have different amounts of 'details' sheets.
SO, my goal is to have a blank in the 'format' sheet that asks how many details are needed. When the user types in 5, the code will add a sheet named '1.5 Detail' to the end of the workbook and have it formatted the same as the other 'details' sheets. Is this possible using VBA? Also, is there a way to make the charts and formulas include the new tab when it is added without manually going and adding it to everything?
Thanks in advance!
Let's say you had three detail worksheets named: d_1, d_2, and d_3.
Each has an Excel Table named Labor with a column entitled "Cost". Each Labor table has a unique number of data rows.
On a summary sheet you could sum all of them like so:
=SUM(d_1:d_3!Labor[Cost])
The above will give you the labor cost grand total from all sheets. It is summing all of the rows from the tables and is not dependent on any summary information in the detail sheets.
So if you add a new detail sheet, d_4, then yes the example formula would need to be updated. HOWEVER, there is an old trick to get around this...
Create two additional sheets with the same tables, but with only one row of ZERO values in each table. Call the first one of these sheets "START". Call the second one of these sheets "END". Place START immediately before the first detail sheet, and place END immediately after the last detail sheet. NOW MAKE BOTH INVISIBLE.
Finally change the example formula to:
=SUM(START:END!Labor[Cost])
Now when new detail sheets are added, d_4, d_5, d_6, d_n, no change needs to happen to the formula on the summary sheet, yet all of the new data are included in the summary calculation.
Use ThisWorkbook.Worksheets.Count to count the number of sheets. Then if it is less, use Worksheets.Add and ActiveSheet.Move After:=Sheets(ActiveWorkbook.Sheets.Count) to add it on to the end.

How to duplicate cell data in excel between rows if the cells are empty when another cell matches

I know the title is really long winded, I will try to explain
I am trying to get Magento products into Zen Cart (background only - shouldn't be relevant).
I have an excel 2010 xls spreadsheet and in it I have a load of product data: skus, prices, categories, etc... you get the idea. I have each of the products along with their data listed once, each with a unique SKU field.
But... Some of these products are in more than one category and the way I am importing, each product needs to be listed multiple times, once for each category.
So, I have done an sql dump which contains two columns; sku and category. I have pasted these values into excel as new rows, so now I have a situation like this (with a lot more entries):
As you can see for each sku (left highlight) there is one entry containing all the data apart from the category (right highlight) and then there is an additional entry for each category it belongs to which contains only the category and sku but none of the other data.
So, what I need to do is some how copy all the data (apart from the categories column) across all cells with the same sku. Does anyone have any idea how I can achieve this without hitting Ctrl+V several hundred times. I realise VBA can probably handle this pretty easily, but I dont have a clue on that front.
Any help greatly appreciated
I hope you’re willing to use a second sheet, and to reference the data rather than actually copying.
On Sheet2, set A1 to =IF(Sheet1!A1="", "", Sheet1!A1).  Drag (extend/fill) this down to A500 (as much data as you have on Sheet1, or further, to allow for growth).  Also drag A1 over to AA1 and then drag that down to AA500.
Then set B2 to =IF($AA2="", Sheet1!B2, B1), drag it to Z2, and drag B2:Z2 down to B500:Z500.
P.S. If any of your data (columns) are dates, you will probably need to explicitly format them as dates on Sheet2.  Ditto for any other values that are formatted any non-default way (e.g., Currency or Percentage).  It may be necessary to do this only to cells that have values in them (and not blank cells).
You don't need VBA, unless you need to do this many times.
Assuming the sheet with your data is called Source and the sheet with the result is called Dest, you can get what you want following these steps on the sheet Dest:
On A1 type =Source!A1
On A2 type =IF(ISBLANK(Source!A2),A1,Source!A2)
Select the range A1:XX1 (where XX is the last column of the sheet Source)
Press Ctrl+R (to copy the first cell to the right)
Select the range A2:XX## (where ## is the last row of the sheet Source)
Press Ctrl+R and Ctrl+D (to copy to the right and down)
Here is an explanation of what's going on:
The first row is copied from the Source as it is.
Each cell of the second row is copied from Source only if that cell is empty, otherwise the cell above is copied.
Here's the quick and dirty solution:
Select the columns you need to be filled
Press Goto Ctrl-G
Special `Alt-S'
Blanks (Alt-K, Enter)
This should select all blank cells. Now type =B2 (assuming you're in B3, i.e. use the cell above the active cell) Important: Press Ctrl-Enter instead of Enter to enter the formula.
Done!
On a new Worksheet get the numbers 1-26 running across the top in Row1 by typing 1 in cell A1, 2 in cell A2, and then selecting those two cells and filling through Z.
Now in A2 type the following formula =VLOOKUP(Sheet1!$A1,Sheet1!$A:$AA,VALUE(A$1),FALSE)
Fill this formula in the Range A2:Z## (where ## represents your last row of data).
Then copy Row1 from Sheet1 to Row1 on Sheet2.
This formula will copy the rows of data straight down into the empty rows below them (assuming the sku only changes where there is a row of new information.
This will then all be active formulas, so I would recommend selecting all on Sheet2 and right-clicking in cell A1, and paste special by value.