Automate Excel worksheet to apply information in specific row to another worksheet - vba

I have 2 worksheets setup in excel. Worksheet 1 is dynamic information that I edit weekly. Worksheet 2 is static and will not change. One column in worksheet 1 numbers that are associated with a particular row in worksheet 2. For example, if worksheet 1 column C has a 4 in it, I'd like to apply what is in row 4 in worksheet 2, to replace that number with text.
Does that make sense?

If as you stated you already have a pre-filled-in column C that maps a row in Sheet1 to a row in Sheet2, then all you need is the INDEX function to pull information from Sheet2 into Sheet1.
You cannot "replace" the number in Sheet1 col C with information from Sheet2; you need to keep it as the row# into Sheet2. So you copy the information from Sheet2 into Sheet1 in some other column on Sheet1. But you can hide Col C in Sheet1 if you do not want to see it for some reason. Or just move the mapping Column in Sheet1 to some column much further to the right.
If you have multiple columns in Sheet2 to move to Sheet1, just use multiple INDEX functions in the proper Sheet1 columns with the proper Sheet2 column numbers.
A trivial example for pulling one data element from Sheet2 to Sheet1 for row 2 in Sheet1 (replace the col#inSheet2 with a Sheet2 column number); the dollar-signs are important:
=INDEX(Sheet2!$A$1:$A$1, Sheet1!$C2, col#inSheet2)
If the rows in Sheet1 change, yet there is a per-row key value that maps rows in Sheet1 to Sheet2, then use the MATCH function in Sheet1 col C to get the row# in Sheet2 that maps to Sheet1. This is particularly true if there are multiple columns of data to transfer from Sheet2 to Sheet1.
And as #L42 mentioned, use VLOOKUP instead if there is just one column to move from Sheet2 to Sheet1, and again the rows from Sheet1 to Sheet2 change weekly, and again there is a per-row key value that maps the two sheets.

Related

Transpose and copy to row to column

I have a row of data in say A1:AA1 in worksheet A. In worksheet B I have a range for data from A1:A25. I need the data from the row in worksheet A to be transposed into the data range in worksheet B. I can Paste Special and paste in the values but I need the information in worksheet A to update automatically that in worksheet B.
Select A1:A25 in Sheet B and enter:
=TRANSPOSE(A!A1:AA1)
with Ctrl+Shift+Enter.
However won't fit 27 columns into 25 rows.

Compare two columns then add another if the data is the same

I have two separate worksheets that I would like to search in and then populate a column if two columns represent the same data. I'm having a hard time explaining this so please have patience.
I have worksheet1 with column "A" having text and numbers in it. In the same sheet column "B" has the data that I want to show in worksheet2 if Both Column "A" match in both worksheets.
Example:
Worksheet1
Column A
Text text text (2012-R-0000)
blah blah blah
text text text (2012-R-0001)
Column B
20-204
20-405
40-609
Worksheet2
Column A
2012-R-0000
2012-R-0001
Column E
(empty) I would like the data in Worksheet1 Column B to be placed here.
Thank you in advance for any assistance with my question.
Assuming your worksheet 1 and worksheet 2 datas starts with A1
use the below formula at worksheet 2 in E1
=VLOOKUP("*"&A1&"*",Sheet3!A:B,2,FALSE)
French Formula:
=RECHERCHEV("*"&A1&"*";Sheet3!A:B;2;FALSE)
and drag down
Proof of Work
Use VLookUp in Worksheet 2 like this.
In cell E1 of Worksheet 2 write the following:
=VLOOKUP(A1;Worksheet1!$A$1:$B$30;2;FALSE)
Then simply drag the formula down. It will match the first column from both worksheets, then paste the corresponding data from column B in worksheet1 to column E in worksheet 2. You'll have to edit "Worksheet1" to match the name of the acctual worksheet, and the number 30 to match the number of rows in worksheet 1.

Copying value from different Excel sheets using some condition

i need it to check if the value in Col A is equal to Value Col A Sheet 2 then copy the values from Sheet2 to Sheet 1 in the respective rows.
In sheet3 enter:
=IF(Sheet1!A1=Sheet2!A1,"Equal","Not equal")
Or check this answer

How do I copy specific cells from sheet 1 and paste into corresponding rows of sheet 2 , based on values of cells in sheet 2?

I have Sheet 1 with lots of columns, where column A is the list of all customer codes. In sheet 2 I have column A as some selected customer codes. Now based on the selected customer codes in sheet2 I need to extract few columns (H,I,J) from sheet1, paste it into sheet 2 and export the result to a new sheet.
Excel noob here. Hope you understood my query.
Assuming customer codes are unique in column A (i.e., the same code does not appear multiple times) you can do all of this with VLOOKUP function.
No need for VBA. In column B, Sheet 2: =VLOOKUP(A1,Sheet1!A:J,8,False) will return the value corresponding from column H (H being the eighth column of the range A:J).
Likewise do this for column I:
=VLOOKUP(A1,Sheet1!A:J,9,False)
And if you guessed also do this for column J:
=VLOOKUP(A1,Sheet1!A:J,10,False)

VBA code to copy rows from one excel sheet to another

The original spreadsheet was from column A to E. I just pasted the numbers in column F from another sheet. My new spreadsheet has 1517 rows and goes from columns A-H. The numbers in column F (row 2 to row 420) are also in column C.
I was able to use the MATCH function of Excel to find the exact position of a number in column C i.e In column C, on which row can I find the numbers that are in column F? For instance, the number "12345678910" in cell F2 can be found in cell C1049,on row 1049. I put those position numbers in a column that I called "index".
Now, the goal is to write a vba code to copy those rows at once. I am trying to extract/copy to another sheet the numbers in column F that are also in column C but I only want columns A to E - from the original sheet. Copy each row number that is in the index column but only the columns A-E. To be clear, "12345678910" is also in cell C1049. "Copy row 1049 from column A-E" and do that for each position number in the index column.
I cannot sort the spreadsheet because the columns A-E are linked. A sort would alter the information. Any help would be appreciated.
A sample of my spreadsheet
Sub filterCopy()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set ws1 = Sheet1
Set ws2 = Sheet2
ws1.Range("A1:F1517").AutoFilter 6, "<>"
ws1.Range("A1:F1517").SpecialCells(xlCellTypeVisible).Copy ws2.Range("A1")
End Sub