Copying value from different Excel sheets using some condition - vba

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

Related

Search column in one Excel workbook to paste Adjacent Cell's Value into active VBA script

I have Workbook1 and Workbook2 and need to search column A in Workbook1 for specific string value and then copy adjacent cell that is in column B of Workbook1 to the macro being run where I need to insert the value in the following formula in VBA script: =(ROUNDUP((F2+40)/[VALUE],0))*[VALUE]. The [VALUE] = the value taken from the adjacent cell in column B from Workbook1. Workbook2 is where the macro is running on.
I am being rushed at the moment and if this is not clear enough. I will come back and clarify as needed.
VALUE = WorksheetFunction.VLookup(theString, Workbooks("Workbook1").Worksheets("Sheet1").Range("A:B"), 2)

Copy data in 1 row in Sheet 1 to changed data in 2 rows of Sheet 2

I am relatively new to VBA.
I have a 10 digit number (1234567890) in A1 of Sheet 1 and want to copy this data in A1 in sheet 2 with a concatenated value (-qwerty) and again in A2 in sheet 2 with another concatenated value (-abcdef). So the final values in A1 of Sheet 2 will be 1234567890-qwerty and in A2 of Sheet 2 will be 1234567890-abcdef
Similarly, I want to fill n rows of A column in sheet 1 to 2n rows of A column in Sheet 2.
Looking out for VBA help in excel for the same.
Thank you in advance.
I think no need a VBA
just write in excel's Sheet2 column A1, a formula
= Sheet1.A1 & "-qwerty"
and just write in excel's Sheet2 column A2, a formula
= Sheet1.A1 & "-abcdef"
or something like that
Direct value transfer with a string concatenation would seem to be the easiest.
sheet2.cells(1,1) = sheet1.cells(1, 1).value2 & "-qwerty"
sheet2.cells(2,1) = sheet1.cells(1, 1).value2 & "-abcdef"
Bulk transfer can be accomplished with a simple formula and more string concatenation.
with sheet2.cells(1,1).resize(99,1)
.formula = "='Sheet1'!A1&"-qwerty"
.value = .value
end with
After the formula has been filled, the value in the cell is reverted to the value from the formula (thereby removing the formula).

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.

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