Column header validation with different sheets using macros - excel

In Excel, I have 4 column headers (Id, Name, Age, Place).
I have 3 Excel worksheets with same column headers and different data.
I want to make a consolidated worksheet and the constraint is I have to check whether the column header is the same in all 3 worksheets and move it into the consolidated worksheet.
In the 1st worksheet I have values in the first row.
In 2nd worksheet, the first row is empty and the second row has data.
In 3rd worksheet, the first and second rows are empty and the 3rd row has data.
The 4th worksheet is the consolidated one. I want all 3 worksheet's data in this sheet.
How to do it with macros in vba?

There's built-in functionality for data consolidation.
You'll need to move your data so it's all on the same row but in the end will probably be much easier than writing code from scratch.
How to consolidate
Follow these steps to consolidate several worksheets into a master worksheet:
If you haven't already, set up the data in each constituent sheet by doing the following:
Ensure that each range of data is in list format. Each column must have a label (header) in the first row and contain similar data. There must be no blank rows or columns anywhere in the list.
Put each range on a separate worksheet, but don't enter anything in the master worksheet where you plan to consolidate the data. Excel will do this for you.
Ensure that each range has the same layout.
In the master worksheet, click the upper-left cell of the area where you want the consolidated data to appear.
Note: To avoid overwriting existing data in the master worksheet, ensure that you leave enough cells to the right and below this cell for the consolidated data.
Click Data → Consolidate (in the Data Tools group).
In the Function box, click the summary function that you want Excel to use to consolidate the data. The default function is SUM.
Here is an example in which three worksheet ranges have been chosen:
Select your data.
More information and the remaining instructions are at the source.
If you want to automate the process, record a macro as you performs the necessary steps and then you can edit as required.
See: Recording a Macro to Generate Code as well as Revising Recorded Visual Basic Macros. If you're not familiar with Excel (or whatever you're planning on automating with VBA), do that before attempting VBA.
This VBA tutorial is highly recommended: Excel VBA For Beginners and Microsoft's Documentation.

Related

Use common dropdown across multiple worksheets to change single cell

I have a large file with a Scenario Manager, where changing a single cell on the Summary worksheet changes the visible scenario throughout the rest of the workbook. Data Tables are working a treat providing the headline values for each option.
I'd like to have a drop down on each sheet that when changed will change the same single cell on the Summary worksheet, so I don't need to go back to the Summary sheet every time I want to switch visible scenarios.
This is a simple process if I'm using macros and would be the solution I'd normally jump straight to. But this needs to be done without macros and this is where I'm now struggling.
Does anyone know if this is possible (without macros) and point me in the right direction?
Josh
You can insert combo box (Developer Tab > Insert > Form Controls > Combo Box) on each sheet. Mention linked cell as a cell of the summary sheet (Absolute reference with sheet name). That cell will give you index of the item selected in the drop down list. Then you can insert index formula in the cell you want to change every time to get value of the drop down list. Once you insert it on one sheet you can copy it to other sheets. No macros required.

Copying data validation from one worksheet to another in an excel workbook

Ive got three worksheets setup.
The first contains reference data for my data validation list.
The second references the first sheet for a data validation drop down list. Something like sheet1!$a1:$a3
The problem arises when I try and copy the cell in sheet two that contains the data validation drop down list to a cell in sheet 3 where the destination cell is empty.
I'm trying to copy excel data validation but when copied across to sheet 3 it references the cells $a1:$a3 but doesn't maintain the reference to sheet1 where the data for the drop down list is actually stored.
How can I copy the data validation such that when it is copied to sheet 3 it still maintains the reference to sheet1 where the static data that makes up the list is.
If I am understanding you correctly, the pasted Data Validation list is not showing the corrrect information. In my workbook I needed multiple cells of DV to display info from the sheet labled "Parts" after they were copied to the sheet labled "Ascending".
What I had to do was select my newly, and thus far incorrectly, pasted material, go to the 'Data' tab and click into 'Data Validaion --> Data Validation' (drop down menu). From here I had to edit the source to reflect the origional sheet.
Was: =$C$4:$C$21
Edit: =Parts!$C$4:$C$21
This determines what sheet the data is being validated from. Once Ive done this, I can copy and paste a DV interal to whatever sheet I am working on.
For some reason naming the range from the origional sheet (Parts) did not carry over in the pasted DV. VLOOKUP and other formulas thankfully work fine.

Automate data transfer between workbooks in Excel

I admit to not being very technical and my limit up to now has been using paste links to connect data between sheets. I now have a requirement I cannot figure out.
I have 2 workbooks I wish to automate sharing data between.
Workbook 1 contains multiple rows of data manually entered.
I need a button against each row so when it is pressed data from certain cells on that row in Workbook 1 are transferred to cells within a worksheet in workbook 2
I would be very grateful for any guidance on how to achieve this.
Many thanks!
Though you can deploy VBA to achieve this, but the same is also possible with simple formula like.
=[1.xlsx]Sheet1!$A$1
Lets say you have two workbooks 1.xlsx and 2.xlsx and you want sheet1/column A1 value from 1.xlsx to be auto populated in sheet1/column A1 in 2.xlsx, you can simply link it with a formula like =[1.xlsx]Sheet1!$A$1 in second workbook 2.xlsx.
So as soon as some entry is done in first cell, second cell is auto populated
However if you are looking only for vba solution do write back

Show multiple drillthrough tables in a single Excel sheet

I need to create a report (for printing) that has two sections. The top section contains the scorecard, and the bottom section contains the drillthrough information for any "red" items in the scorecard.
The scorecard is currently a PowerPivot table with conditional formatting. If the scorecard has 3 "red" cells, then I can double-click on each of the red cells to drillthrough to the details. However, I would like to display those 3 drillthrough tables in the same worksheet below the scorecard, so I can print both the scorecard and the drillthrough details all at once.
I'm looking for a solution that is automated. Each time I print out the report, I can do a lot of copy and paste, but I rather not. I'm looking for a solution that is as automated as possible - so the bottom section of the report will always contain details for anything that is red in the scorecard. I'm open to using VBA.
Thanks!
I would suggest to use VBA. However first store a list of sheets in one of your sheets for your VBA code to use. Create the following subroutine in your Workbook code section to have the trigger for when a new sheet is selected:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Now add code to this subroutine to verify if the sheet selected was already present in your workbook by checking against the list.
If it wasn't in the list yet, check if there is a table on the sheet.
If there is a table on the sheet have its content copied/moved to your report sheet to a specific range and delete the drill through sheet again (and remove it from the list). Have the code select your report sheet again!
If there was NO table on the sheet add it to the list of sheets

Insert a Row to a Specific Set of Columns

I'm working on a spreadsheet to act as a master copy for some important information that will be kept track of for a project. On the main sheet I have a table for notes and a table for contacts set up separated by several columns and some VB code to insert new notes or new contacts. However, when I insert a new note I want it to appear at the top of the table and to move all existing notes down a row. Is there any way to add a row to a specific set of columns so that any other data that is kept on cells with the same row, but in a different table, are not moved?
A basic example:
Dim rng As Range
Set rng = Worksheets("Sheet1").Range("A2:D2")
rng.Insert Shift:=xlDown
...assuming that you want to insert 1 row of cells above the cells currently located in A2:D2.
You'll have to code a VBA macro that selects all cells in the notes table as a Range object, and then moves them down one row.
I wouldn't know the exact code, but I'd advise you use the "Record Macro" function and do it by hand: select two cells in an Excel sheet, press the right mouse button and click "Insert". Then it'll ask you if you want to move the rows down. You can see in the newly recorded macro what the code is, and adjust it for your specific purpose. Good luck!

Resources