create list in excel based upon specific cells by pulling data from multiple sheets - vba

I need to create a list based upon a matrix template from multiple sheets within the same workbook.
I've got a grid that looks like the below:
A1 Expert
A2 Intermediate
A3 Foundation
B4 Grade 1
C4 Grade 2
D4 Grade 3
So if the word "completed" is in cell B3 for instance, then the person has completed Foundation grade 1.
This will be the same template with a new worksheet for each person. The front worksheet needs to have an option to search who has completed what grade. For instance, "Bruce Wayne" sheet name has the word "completed" in cell C2 in his grid (so he has completed grade 2 intermediate") and when I search on the front worksheet for grade 2 intermediates to find out who has this, Bruce Wayne will appear in a list (along with anyone else who has that grade showing "completed" on their worksheet)
I know how to make a macro button, i know how to make a data validation list,
and I've found a macro to loop through all worksheets (https://support.microsoft.com/en-hk/help/142126/macro-to-loop-through-all-worksheets-in-a-workbook)
What I don't know is how to get it to return the sheet name (bruce wayne) to form a list on the front page of names rather than just the value (completed/in progress etc) and what is the simplest way to report it:
1.create a button for each grade/level option that populates the list of sheet names (that would total 9 buttons in this example)
create 2 drop-down list boxes, one with Grades and one with levels and then say if grade 1 and foundation are selected from the drop-down list then it populates the sheet names in another column next to them.
The tab name is created from a "rename sheet" macro which works fine:
https://www.extendoffice.com/documents/excel/2905-excel-rename-sheet-based-on-cell-value.html
so it doesn't necessarily have to report back the sheet name, it could just report back a separate cell that dictates the sheet name if that's easier.
I'm more confused after typing that than I was before! Can anyone understand this/help me?!
Sub LoopThroughSheets()
If worksheets ("OVERVIEW") GOTO C5="Grade 1" And E5="Foundation" Then
' I want this bit to say if the overview worksheet cell C5 contains grade 1 and cell e5 contains foundation then
'
=IF E13="completed", THEN ActiveSheet.Name = Range("I5:I11").Copy)
' I want this bit to then say if the word completed is present in cell E13 on any of the subsequent sheets it should copy the sheet name to the overview sheet in cells I5 to I11'
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
Next ws
End Sub

A worksheet object has a Name property in VBA, which can be accessed. Check out the documentation.
If you need more specific help, please post code.

Related

Extract data from another workbook using VBA

I have two workbooks.
In Workbook A, I want to find the value in cell A11 (sheet 'Data') in column A of Workbook B and then return the corresponding value in column H. THis value must be pasted into Cell C11 in Workbook A.
Workbook B must be opened and closed to extract this data without the user having to manually open it.
How do I use a VBA code to achieve this? Preferably variables are built in based on values in workbook A e.g. path, file name, worksheet name, column A in above example and column H in above example).
Link to Workbook A: https://www.dropbox.com/s/e6ixr5ky4i2r6vw/Data%20extraction.xlsm?dl=0
I'm using MS Office Excel Professional Plus 2010. As long as the user won't be storing file B where he can't access it again, Excel can manage this without the need for VBA.
In cell C11 in workbook A type "=" to begin writing a formula. Now switch windows to workbook B and click cell A11 on sheet 'Data'. Hit 'Enter' on your keyboard... the computer should return to workbook A.
The formula in C11 now should show the filename of workbook B and the cell reference.
Now's when the magic starts: Excel has made this formula into a "Data connection" and will work behind the scenes to keep this cell updated. It may give you a yellow bar asking to activate automatic data updates, which you should accept.
Test and see if this method satisfies your requirement. If workbook B is stored in a shared location, do more testing to see if that doesn't mess it up.
Good luck!

I need to generate new workbooks using existing sheets that I will autopop with data

I have two sheets on my template. Sheet one contains a SKU in column A and a descr. in column B
On sheet 2, I have a pre-written template that has generic SKU and Description. That means under the item sku, it says D999 and under the description it says xxx.
I want to replace "999" with the value in A2 on my first sheet, but the 999 is in multiple columns through the sheet. Next, I want to replace the "xxx" with the data in B2 from sheet 1. I can't seem to find a VBA code that will do this specifically.
Lastly, once the find and replaces are done, I need to have it save me a new workbook using sheet2, in the same format, and name it as the value in A4 on sheet 2. I think you should be able to find the workbook here My Workbook
Basically, I want to be able to enter a bulk amount of new SKUs and Description, and be able to generate a new workbook for each SKU I enter. Right now I have 78 waiting to have sheets made.
In the cell to the right of the cells where you want to type in the SKU, add the following formula: =Match(A2, LookupsheetName!B:B,0). This will return the row the SKU was found on. In the next cell to the right use the Index function: =Index(LookupSheetName!A1:B1000, B2, 0). This will bring the label in column B to the current page. The Match function locates the row the SKU was found on.
Try these for looking up the information, because they are more efficient than VLookups.
The code for copying a worksheet to another workbook can be created using the Macro recorder on the Developer tab. Turn the recorder on then do the steps to manually move/copy to another workbook. When done, open the VBA editor and figure out how to save the workbook to a new name each time.
Good luck.

Hyperlink after Vlookup

This simple thing is eating my brain out. Here is the challenge:
I have 2 sheets in the same workbook. Say Sheet 1 and Sheet 2. I want to Vlookup for the value present in Sheet 1 Column A and Sheet 2 column B. If the value is found i want to put a hyperlink in Sheet 1 Column A to point it to Sheet 2 Column D. In simple words, there are program names present in both the sheets and associated risk in sheet 2. If the program is present in both the sheets then i want to navigate directly to the risk present in the Sheet 2 upon clicking the program name in Sheet1.
I am attaching the sample file with this thread. Please somebody help me. I have tried with vba and normal formulas. Nothing is being worked out.
SAmple file can be downloaded from here
Here's how you can do that with a formula. You'll need to change the workbook name in the HYPERLINK formula to match yours.
=IF(ISERROR(VLOOKUP($A1,Sheet2!$B:$B,1,0)),"",HYPERLINK("[StackTest.xlsx]'Sheet2'!D"&TEXT(MATCH($A1,Sheet2!$B:$B,0),"#"),"Click Here"))

Excel VBA - Pull data from external books and paste into the next blank row in multiple tabs

I'm working on automating a workbook in Excel, and I'm running into a few issues with my VBA code. I'd paste it here, but I've been through so many iterations, it's pretty unusable.
The goal is to have the active book 'grab' the data out of several workbooks containing raw data when it is opened, and put the copied data into a few tabs that can be used to populate various charts on a dashboard tab. Each workbook containing raw data should go into its own separate tab within the active workbook. Broken into steps, I am thinking I need the below process to occur:
Open Active Book
Open hidden tab 'Sheet1'
Open raw data book 1(e.g. c:\Raw Data.xls)
Copy data from specified location (e.g. [Raw Data.xls]Sheet1!$A$3:$AE$64) in the raw data book 1
Paste copied data into Active Book, into specific worksheet, into first empty row (e.g. [Active Book.xls]Sheet1!first empty row)
Hide tab 'Sheet1' in Active Book
Close raw data book 1
Repeat process using raw data book 2 and sheet2 of Active Book
Repeat process using raw data book 3 and sheet3 of Active Book
Only after data is populated into the destination tabs (Sheet1, Sheet2, Sheet3 in the Active Book), can the user interact (click into cells, change tabs, etc) with the workbook
I know this is simple - I'm getting frustrated, as I'm a newbie and the syntax (and multiple variations of syntax) is really throwing me for a loop. Any help would be greatly appreciated. Many thanks in advance!!
Where are you getting stuck? Briefly:
Open Active Book
If its active, it's already open? Reference with object 'ThisWorkbook'
Open hidden tab 'Sheet1'
You don't need to unhide sheets to "VBA" them... If you're going to be creating new sheets for each datafile I'd recommend creating new via:
Set wsDestination = thisworkbook.sheets.add
wsDestination.visible = xlSheetHidden ' Might as well hide it now
If you're wanting to match specific raw data files with specific worksheets, maybe use a "select"
Open raw data book 1(e.g. c:\Raw Data.xls)
Set wbSource = Application.Workbooks.Open("c:\Raw Data.xls")
Set wsSource = wbSource.sheets(1)
'If need Select (see above):
Select case wbSource.name
Case "Raw Data A.xls" ' If line above changes to .Open(Workbooks[i]) or something
set wsDestination = sheet1
Case "Raw Data B.xls"
set wsDestination = sheet2
'...
End Select
Copy data from specified location (e.g. [Raw
Data.xls]Sheet1!$A$3:$AE$64) in the raw data book 1 Paste copied data
into Active Book, into specific worksheet, into first empty row (e.g.
[Active Book.xls]Sheet1!first empty row)
intBlankRow = Application.WorksheetFunction.Counta(wsDestination.columns(1)) + 1 ' Note this only works if there are no blanks in column 1 otherwise you'll need another method: there are some good tricks if you google "find last cell vba"
wsSource.cells.copy wsDestination.cells(intBlankRow,1) ' No need to copy and paste in seperate lines: you can just pass destination to the copy function
Hide tab 'Sheet1' in Active Book
You don't need to
Close raw data book 1
wbSource.close
Repeat process using raw data book 2 and sheet2 of Active Book Repeat
process using raw data book 3 and sheet3 of Active Book Only after
data is populated into the destination tabs (Sheet1, Sheet2, Sheet3 in
the Active Book), can the user interact (click into cells, change
tabs, etc) with the workbook
Wrap the whole thing in a big loop... If you wanna do it the easy way, create an array with your workbook names and iterate through it. Otherwise present the user with a FileDialogue so they can select the workbooks they want to import... this ofcourse depends on what I was saying above: do you want to create new worksheets each time or import specific raw data in to specific sheets...

Get data from sheet depending on cell value

I have a spread sheet that has multiple sheets, the first being "Main Sheet". The subsequent sheet names are the same as the values in column A of "Main Sheet".
Eg:
Main Sheet
Column A5 = 12345
Column A6 = 23456
I want to get the value of cell "Main Sheet"(B5) from sheet "12345"(B10) (the value in "Main Sheet"(A5)) and the value of cell "Main Sheet"(B6) from sheet "23456"(B10).
As the "Main Sheet" is continuously growing, I need to do this by a formula.
Any suggestions?
Your notation makes it seem like you're not using MS Excel, but if you ARE, this should solve your problem.
You will want to use the INDIRECT function. It will turn a string into a reference to a cell.
This means that you can do something like the following (in B1 of Main Sheet):
=INDIRECT(CONCATENATE("'", 'Main Sheet'!A1, "'!B10"))
Assuming that:
'Main Sheet'!A1 == abc123
The formula will give you the contents of:
'abc123'!B10