Workaround for either my approach or the 256 character limit in Excel VBA - 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)))))))),"")

Related

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

Duplicated cells skip 10 rows

I have an Excel spreadsheet with two sheets, Sheet 1 contains some text and formulas I wish to duplicate down to write 2,000 odd lines of C# code for my project. Extremely repetitive, so I thought I could use Excel to write it for me. Sheet 2 contains an extract from my database which I wish to use to populate that values with. My section of Excel code looks like this and is spread out over 10 rows and 5 columns:
new AccountingPeriod()
{
MonthCovered="=Sheet2!B2",
StartDate=DateTime.Parse("Sheet2!C2"),
EndDate=DateTime.Parse("Sheet2!D2"),
AccountingPeriodDescription="Sheet2!E2",
Active='=Sheet2!F2',
April='=Sheet2!G2,
TaxYear="Sheet2!H2"
},
When I highlight these 10 rows and use the Excel duplicate tool I want the cell references (for example, in my spreadsheet Sheet1!D3 = Sheet2!B2, I want Sheet1!D13 = Sheet2!B3 NOT Sheet2!B13) to increment by 1, not 10 as it's doing in my spreadsheet.
We have tried an alternative solution of writing a macro to insert 10 blank rows in Sheet2 for every populated row so that the duplicated references are correct in Sheet1 but we're currently failing miserably at getting that to work correctly.
Instead of a direct reference that is going to change on a 1-to-1 with the copy, use the INDEX function with a little maths to achieve the 10-to-1 row stagger.
In Sheet1!D3 this references Sheet2!B2.
=INDEX(Sheet2!B:B,INT(ROW(1:1)/10)+2)
In Sheet1!D13 this references Sheet2!B3.
The OFFSET function can accomplish the same thing but it is a volatile function that recalculates whenever anything in the workbook changes. INDEX provides the same functionality while remaining non-volatile and will only recalculate when something that affects its returned value changes.

Splitting data between worksheets depending on status of Column A

I have been asked to create a database of volunteers in Excel. The main worksheet (called Data) holds all the information – names, addresses, numbers, reference checks, placements, supervisors, etc. What I am trying to achieve is for the relevant information to be moved from one worksheet to another when the status of the person changes.
There would be 5 categories which the volunteers would fall under (column A labelled ‘Status’)
PROCESSING
ACTIVE
ON HOLD
BARRED
STOPPED/RETIRED
What I want to get is a live database so the information would appear on a relevant worksheet whenever the status on the main spreadsheet changes , but I only want some information to show depending on the category…
Each Worksheet would contain columns A-F from the ‘Data’ worksheet and in addition:
Processing would contain columns X-AE
Active: AF-AW
On Hold: AZ-BC
Barred: AX-AY
Stopped/Retired:- BD-BH
I have searched and searched again but I know nothing about Macros (and my IT department is unable to help) So my question is – is this doable and if so is anyone able to help me?
I hope I am making sense and if not I can email across the dummy database with some made up names to show what it is I am trying to create
You can do this using array formulae. This link shows a simple example which provides the basic formula (explained in detail in the linked article)
=INDEX(range,SMALL(IF(col=value,ROW(range)),ROW(1:1)),COLUMN(A2))
Where range is the range of all your data from your main worksheet and value is the value you want to screen for (this changes for each of your sheets) and col is the column on your main sheet that you want to check the values of. Note it is an array forumla so you have to press control+shift+enter after typing in the formula as explained at the bottom of the link.
You will notice that I have changed the formula to say COLUMN(A2) instead of 2. This is so that you can drag the formula across the columns as well as down the rows. You might need to make this COLUMN(A2)-x where x is an offset because your data don't start in column A.
Note that the same applies for the ROW(1:1) part, if your range doesn't start in row 1 then you will need to offset this by some value as well (i.e. something like ROW(1:1)-y)

Trying to use excel formula or VBA

I have two different workbooks. Book 1 and Book 2 both have the same number of columns A through M.
I want to do match the records between two workbook, for example: I have a column A name Birthday, Column B City, Column C Passport Number......., in worksheet 1 & 2. I want to match worksheet 1 Cell A1 from the Range A:A worksheet 2, If the record in column A cell 13 not matching it shows Birthdate not match in N13 Workbook 2, If it does not match with worksheet 1 Cell 13 from the Range B:B worksheet 2 it shows city not MATCH in Column N 13 in workbook 2, and so on till column M.
I am using the formula below but it's not working properly, I don't know what I am missing and what formula should I add in. I have no idea about VBA. But I want to see is it easier to do by using excel formula or vba?
IF(COUNTIF(Target!$A$2:$A$5964,Source!A8)=0,"Birthday",IF(COUNTIF(Target!$B$2:$B$5964,Source!B8)=0,"City",IF(COUNTIF(Target!$C$2:$C$5964,Source!C8)=0,"Country",IF(COUNTIF(Target!$E$2:$E$5964,Source!D8)=0,"Passport Number Mismatch in Target",IF(COUNTIF(Target!$F$2:$F$5964,Source!E8)=0," Travel Date Mismatch in Target",IF(COUNTIF(Target!$G$2:$G$5964,Source!F8)=0,"First Name Mistmatch in Target",IF(COUNTIF(Target!$H$2:$H$5964,Source!G8)=0,"Full Name Mismatch in Target","Match in Target")))))))
Thanks in Advance.
VBA has access to these same worksheet formula functions (e.g. COUNTIF): there really aren't column or matrix functions that VBA has that formulas don't have.
However, VBA lets you write loops (e.g. while, for), it allows if-statements, procedure calls, and many lines of code so your calculations can have more steps and hence be more complex. VBA also lets you have temporary space in the form of arrays (and strings and objects, too) (so you don't necessarily need to use columns for temporary space as one might do with formulas). VBA also allows recursion, which makes some calculations easier (to some definition).
VBA provides an imperative programming model. VBA procedures can read and write any cell of the spreadsheet. Imperative programming, on the other hand, needs to be triggered somehow such as by using a button.
By contrast, the data-flow programming model with formulas will automatically recalculate whenever their input sources change, which is good. But there are some cases it doesn't handle naturally (e.g. recursion).
Another option is to combine VBA with formulas, by writing new formulas that are then implemented in VBA. If you are doing that, the VBA can only return information thru function return values; it cannot otherwise modify the spreadsheet.
So, if you can think of how to do this easier using loops (and arrays) or recursion and maybe with a button to trigger the computation (or by using custom formulas) then VBA might be interesting.

Combine Columns in multiple Excel workbooks and auto-de-dupe

I have three workbooks with IDs in column A. I want to create a fourth workbook, which should combine the IDs and de-dupe them automatically so that I can perform a vlookup on them to reference data on the other workbooks. The 3 workbooks with data in them will be constantly updated with new ID numbers added, so I need the master/summary workbook to automatically grab newly added ID numbers and perform vlookups against the other workbooks.
The goal of this is to give a summary view of each record (which corresponds to a person), letting the user know which workbooks that person exists in.
I have tried doing =max() to retreive the number of ID's in each workbook, and combining them, telling me the total # of ID's that exist, combined. Then I tried to perform this: =SMALL(IF(FREQUENCY(Test1:Test2$A$2:$A$1000, ROW($1:$28))<>0, ROW($1:$28), ""), ROW(A1))
+ CTRL + SHIFT + ENTER
But I'm 1. not sure if that'll work and 2. not sure how the syntax works with 3 separate workbooks.
I also tried the union method in VBA with no luck - again I think I'm messing up the syntax.
You can retrieve a unique list of the id numbers in [ID_First.xlsx]Sheet1!$A$2:$A$999 using the following array formula in the master worksheet's A2 (needs a row above it to avoid circular references).
=IFERROR(INDEX([ID_First.xlsx]Sheet1!$A$2:$A$999,MATCH(0, IF(LEN([ID_First.xlsx]Sheet1!$A$2:$A$999),COUNTIF(A$1:A1,[ID_First.xlsx]Sheet1!$A$2:$A$999),1),0)),"")
If you stack similar formulas consecutively, passing calculation on to them with IFERROR(), you can gain a unique list from three separate workbooks.
=IF(LEN(A1),IFERROR(INDEX([ID_First.xlsx]Sheet1!$A$2:$A$999,MATCH(0, IF(LEN([ID_First.xlsx]Sheet1!$A$2:$A$999),COUNTIF(A$1:A1,[ID_First.xlsx]Sheet1!$A$2:$A$999),1),0)),IFERROR(INDEX([ID_Second.xlsx]Sheet1!$A$2:$A$999,MATCH(0, IF(LEN([ID_Second.xlsx]Sheet1!$A$2:$A$999),COUNTIF(A$1:A1,[ID_Second.xlsx]Sheet1!$A$2:$A$999),1),0)),IFERROR(INDEX([ID_Third.xlsx]Sheet1!$A$2:$A$999,MATCH(0, IF(LEN([ID_Third.xlsx]Sheet1!$A$2:$A$999),COUNTIF(A$1:A1,[ID_Third.xlsx]Sheet1!$A$2:$A$999),1),0)),""))),"")
Array formulas require Ctrl+Shift+Enter to finalize. Once entered correctly, fill down as necessary to collect all unique IDs.
With a unique list of id numbers, you can use the same method of nested IFERROR functions to look through a series of three workbooks for additional data.
=IFERROR(VLOOKUP($A2, [ID_First.xlsx]Sheet1!$A$2:$Z$999, 2, FALSE),IFERROR(VLOOKUP($A2, [ID_Second.xlsx]Sheet1!$A$2:$Z$999, 2, FALSE),IFERROR(VLOOKUP($A2, [ID_Third.xlsx]Sheet1!$A$2:$Z$999, 2, FALSE),"")))
I'm offering this as you've mentioned a total of 50 member IDs. This method can quickly (and logrythmically) eat up calculation resources when applied to larger groups of numbers.
If you've got Excel 2016 or later, you could unpivot the data using PowerQuery, which is now built in to Excel under the Get & Transform section of the Data tab in the ribbon. Plenty of examples of how to do this if you search Google for 'unpivot' and 'Powerquery'.
If you have Excel 2010 or 2013, you can download the PowerQuery addin for free from https://www.microsoft.com/en-nz/download/details.aspx?id=39379 (assuming IT let you do so).
PowerQuery is a revolution in Excel data transformation, and the learning curve is a lot less steep than advanced formulas or VBA.