VBA code to copy rows from one excel sheet to another - vba

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

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.

add a value to column E if Column A has a value >0 on the same row VBA

How can I add a Cell Value from another Sheet to a Column E as long as the Cell in Column A is >0. I need it to move down a Row if true and end or 'go to line' if = 0?
Sheet1 has the one Cell needed for the Copy and Paste Value.
Sheet2 has a Table that spans from Column A to Column E.
This will be Looped through many Workbooks and there are an unknown amount of Rows.
I am using Excel. How should I start this VBA. I can't seem to figure out how to drop down a row for both columns.
Any and All suggestions will be appreciated, thanks.

Excel - Have a value from column B of a 2 column reference pasted anytime the value from column A is entered on a separate worksheet

In the example I have a 2 column reference where data in column E is correlated to column F. I need the data in Column F to show up anytime data from Column E is entered in a separate worksheet if possible.
To be clear, is it possible to enter data in Column A of Sheet 1 that pulls the correlated data from column B in reference Sheet 2 and enters it into Column B of Sheet 1?
I tried using a simple function in a single sheet but it obviously doesn't do what I need.
You are after VLOOKUP or INDEX MATCH
Sheet1 b1 and fill down rows
=IFERROR(VLOOKUP(A1,Sheet2!E:F,2,FALSE),TEXT(,))
Or
=IFERROR(INDEX(Sheet2!F:F,MATCH(A1,Sheet2!E:E,0)),TEXT(,))
If you set you data up as tables the formulas will autofill down. Rather than use entire columns you can set to the ranges containing data.
Data:

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.

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

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.