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

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.

Related

Excel VBA - How to copy rows based on a criteria from multiplesheets into one sheet

I've have a spreadsheet with multiple sheets and a need to copy specific rows based on a criteria (a specific month). So the idea is to be able to loop through the other sheets and copy rows (for example all rows with June in column 1) onto the sheet "Consolidated Data" from all the country files without touching the "Do not include" sheet.
Thank you!
You have to be more specific - do all the country pages look the same? How are you indicating the criteria (i.e. June), and what do you want the consolidated data tab to look like?

Copying multiple results based on a drop-down list

I'm pretty new to creating Macros in Excel and using VBA.
Let's say I have a model based on a drop-down list. Based on the item selected from that list, model analyses according data and creates results. My point is to have these results compared for all the components from the list, in another sheet. The problem is that list includes around 200 item numbers.
What I need my macro to do is:
Choose the item number from the drop-down list in cell A1 in the "Sheet1"
Copy the range A1:E2 in the "Sheet1"
Paste the results to the Range A1:E1 in "Sheet2"
Go back to "Sheet1" and choose next item from the list
Copy the same range
Paste it to "Sheet2" one row below the previous one (creating a list)
And repeat the action until the last item on the list is used.
Does anybody have any advises how to write this macro down?
The task is by far exceeding my current programming skills. I searched everywhere, but couldn't find anything what would guide me into solution.
I implemented what you want on an Excel workbook with two sheets. Download it here:
http://s000.tinyupload.com/?file_id=05985444391023940738
Try this. Does it do what you need?

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)))))))),"")

Excel - Can not compare two spreadsheets

I have gone through V-look-up guides online but I can not find one that explains what I am looking for. I am trying to avoid manual checking.
What I have:
Two sheets, Sheet 1 and Sheet 2. Both sheets have the same column names (A1:G1) with multiple rows.
Sheet 1 contains my spreadsheet where I update daily. Sheet 2 is the same spreadsheet that is imported from a application (but has hourly updates). Data can change in each row (for some columns) along with additional added/deleted rows. The data is text, dates and numbers (mixture of both too).
I want to run a formula to highlight the changes on sheet 1 (grabbing the updates from sheet 2. Once I find out the formula works correctly, I would like to know how to replace the Sheet 2 updates onto my spreadsheet (Sheet 1).
I am looking for a formula outside of creating a macro (worst case scenario).
Currently I have the following vlook up formula:
=VLOOKUP(A1,sheet2!$A:$A,1,FALSE)
When I run this in another column (lets say in H1 in Sheet 1), it will display "N/A" if that column (A1) in Sheet 2 is not the same. If it is the same, it will write out the column name.
When I use the following formula highlighting all the cells in Sheet 1, I get a values error:
=VLOOKUP(A1:G33,Sheet2!$A:$G,1,FALSE)
How could I apply that formula to the whole spreadsheet (I guess it would apply to both sheets) and have it highlight records in my spreadsheet (Sheet1). Could it also highlight rows that are missing or added?
The data in Column 1 and 2 would never change (they are ticket numbers). Only change that can apply is if ticket is closed, so when I import the updated spreadsheet that row isn't there anymore. If you think there might be a better way to tackle this down, I would like to hear.
Please let me know if I am not clear.
Here are some example screenshots:
Just in case, the formula for the totals are (adjusting the columns for each):
=SUBTOTAL(3,INDEX(C:C,2):INDEX(C:C,ROW()-1))
Sheet 2 is setup very similar. When I import it into excel, the columns are the exact same as Sheet 1, the only difference can be more/less rows (along with the updates for each row).
You can use conditional formatting.

Excel: How to compare sheets from 2 different workbooks for differences

I have an original excel file that I have ran a simulation that inputs financial data. I made a copy of this file, and wired the formulas up differently to try and increase calculation performances.
I now have 2 workbooks, the original and the final. I want to compare each sheet from each of the workbooks together to make sure that the financial numbers have remained the same, to make sure the new formulas are not effecting the numbers received.
I have tried to put copies of the two sheets into one workbook, name them April12 and April15. Then insert a third sheet. In cell A1 of the third sheet, I wanted to use the formula
=April12!A1=April15!A1
to get TRUE/FALSE values. But the formulas in these sheets reference many other sheets that are not in this new workbook, so all of my numbers turn up as #REF.
Iv googled many different ways of approaching this but I cant seem to get any of them to work. Does anyone know a simple way I can compare just the values from 2 sheets from 2 different workbooks to find out if the numbers have remained the same or have changed?
Note:I am using excel 2010.
I think you already know how to verify data using formula so is the problem to refer to a row in a different workbook ? if so, following might be helpful :
=[yourFile.xls]SheetName!$Col$Row
this way you can update your formula like(yourFile.xls refers to the complete path including the file name) :
=[file1.xls]April12!A1=[file2.xls]April15!A1