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

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.

Related

Auto populating rows from another sheet conditional to a specific cell value

Hello i am trying to autopopulate rows from another sheet if a specific value if found in a specific cell. So far, i managed to do it manually by adding this line in Sheet #2 for each cell.
=IF(OR('Le 2250'!$C48="Nouveau locataire",'Le 2250'!$C48="Décès", 'Le 2250'!$C48="Retention"), 'Le 2250'!$B48,"")
I am trying to create a vba script that will generate each column in Sheet#2, and that will dynamically update regarding if i add a row in Sheet 1 or delete it.
Sheet1 is:
Sheet2 is:
Your help is appreciated
What your looking for is the INDIRECT function
As an example:
=CELL("contents",INDIRECT("Sheet1!B5"))
This always pick up the value in Sheet1 Cell B5, regardless of changes in Sheet1.
For more information: Excel INDIRECT Function
Edit: To directly answer the question with INDIRECT.
=IF(OR(INDIRECT("'Le 2250'!C48")="Nouveau locataire",INDIRECT("'Le 2250'!C48")="Décès"),CELL("contents",INDIRECT("'Le 2250'!B48")),"")

Transferring information from input sheet to master sheet

I am trying to move data from one workbook 'input worksheet' to another workbook 'master workbook'. Both sheets are in the same file and if possible, it would be great if both files didn't have to be open at the same time in order to transfer the data but the master workbook would autosave once the data was transferred across. Links to images of the files below to make it easier to understand what I am trying to do.
The data in the input worksheet is in row 6, columns A-J with each user inputting details of the tasks they get asked to complete. I would like when a button is clicked, the data from the input worksheet is transferred into row 2, columns B-K in the master workbook so that each time a new task is entered and transferred across, it appears in the row below (so that it can be pivoted later, etc.).
http://i.stack.imgur.com/b2cyI.jpg - input sheet
http://i.stack.imgur.com/JZr0a.jpg - master sheet
Use the macros here to get the last row in the master sheet.
Then simply write the values from the input sheet to the corresponding cell in the master sheet.
That is all. This is how you refer cells:
tbl_master.cells(1,3) = tbl_input.cells(3,5).value
Make sure that the row in the tbl_input is a variable, coming from the function, calculating the last row. Give it a try!
Edit:
This is what I use for last row:
Public Function last_row_with_data(ByVal lng_column_number As Long, shCurrent As Variant) As Long
last_row_with_data = shCurrent.Cells(Rows.Count, lng_column_number).End(xlUp).Row
End Function
If you want to find the last row of column B of sheet "tbl_main" you call it like this:
last_row_with_data(2,tbl_main)
Edit2:
Change the names of your sheets here, and reference them by their names.
In order to get this window, select the sheet on the left and press F4.

Lookup function in multiple sheets data

I have multiple sheets of data and I want to make it in one sheet (All of them are in the same workbook). Link to the excel file.
I tried to use Hlookup function in excel file, something like below:
=HLOOKUP("University",Sheet1!$A$1:$G$2, 2, FALSE).
But, since I have more than 100 sheets of data, I want to find a way to drag the function and auto generate the function below the 2nd row. I have tried to use indirect function by setting a reference column in front as below but cannot deal with it.
=HLOOKUP("University", 'INDIRECT(A3)'!$A$1:$G$2, 2, FALSE)
My next option is VB code. But, I am new to VB. Anybody can help on it?
Place your individual sheet names in column H of the Summary sheet and the row number in column I (as helper columns) and write this formula in cell A2 of the summary sheet.
=IFERROR(HLOOKUP(A$1,INDIRECT($H2&"!A1:G"&$I2),$I2,0),)
and drag to column F and down for as many sheet rows combos you have. I used 10 rows but you can obviously make it longer or shorter as neeed.
When you are done you can filter on 0 in column A and remove any lines with no data.
If your sheet names have spaces in them, you'll need to adjust the INDIRECT formula to this:
INDIRECT("'"&$H2&"'!A1:G"&$I2)
best way would be "defined names" + INDIRECT + HLOOKUP (or LOOKUP) like:
defined names
name: SList
formula: =MID(TRANSPOSE(GET.WORKBOOK(1))&T(NOW()),FIND("]",TRANSPOSE(GET.WORKBOOK(1))&T(NOW()))+1,255)
formula in cells: (this in A2 then simply autofill to G2 and thenn everything down) (you'll get a row with 0's between the sheets, which can be filtered out or deleted later (copy/paste values))
=IFERROR(HLOOKUP(A$1,INDIRECT("'"&INDEX(SList,COUNTIF($A$1:$A1,0)+2)&"'!$A:$G"),$H2,0),"")
Set H2 to 2 and for H3: (autofill down from H3)
=MAX(($H2+1)*($A2>0),2)
works perfectly for me LINK
No manual typing of sheetnames or something like that (only Column H:H as helper). Youll get rows's with 0's every time a new sheet is selected which can be filtered out. (or if you copy/paste values also can be deleted)
the +2 at ...st,COUNTIF($A$1:$A1,0)+2)&... simply tells to start with sheet 2 (if summary is the first). You may change it to +1 if you want to lookup starting with the first sheet.
Assuming you already have all 100+ sheet names typed out in column A, this will work whether or not you have spaces in the sheet names:
=HLOOKUP("University", OFFSET(INDIRECT(ADDRESS(1,1,1,1,A2)),0,0,2,7),2,FALSE)

vlookup not finding vba cells

I have a table that uses a bit of vba to populate column b with id numbers.
I then have column c as a vlookup that gets a name based off the id, from another sheet. The vlookup in the first cell works fine and returns the correct name, John Doe.
When I drag down, the rest of the cells in column c return the same name as the first, John Doe. The vlookup in the other cells is exactly the same, except the reference cell does change, as expected....so, c2 = vlookup(b2, $range, col, false), c3= vlookup(b3..), c4=vlookup(b4,..), etc.
The catch is, when I look at the vlookup in c3 and click on b3, the cell changes to find the correct name (no longer John Doe). So it works fine. And I have to do that for every cell in column c.
It's like vlookup isn't aware that column b changed? Is that something that happens with vba? Is there a refresh command or some other way for vlookup to register that column b has changed without having to click on each individual vlookup function?
If you've entered a formula in a cell, then copied the formula to another cell and Excel hasn't updated your results, that means that Calculation Mode is Manual.
To fix it (depending on version, this is for Excel 2010)
Click on Formulas in the Ribbon
Click on Calculation Options
Click on Automatic
If you need to have it calculate manually (valuable for making many formula changes in a large worksheet):
Click on Formulas in the Ribbon
Click on Calculate Now to calculate the entire workbook, or
Click on Calculate Sheet to calculate the current worksheet
You can skip all the clicking by pressing F9 to Calculate Now or Shift-F9 to Calculate Sheet.

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