Hi all,
New poster here, and I was hoping to get some help with a macro for Excel 2007. I have a working understanding of programming in Java and C++, but teaching myself how to write macros in Excel is apparently beyond me. I want to write a macro that would be able to
1. Take the contents of each cell in Column K of sheet 1 and search for it in Column A of sheet 2
2. If the value is found, copy the entire row that the value is found in and paste it back to sheet 1 , starting from column L of the same row as the cell that was initially searched for.
3. If the value is not found, move on to the next cell of Column K.
for example, the program should start with finding the contents of cell K1, searching for it in the entire Column A of Sheet 2, and if it is found in, lets say, row 3, the macro will copy the entire contents of row 3 and paste it to sheet 1, L1 and beyond (depending on how many cells were in the row). Then it will move on to K2 and perform the exact same actions.
If I were to approach this in Java, I would use nested loops, with one going through every cell of Sheet 1 Column K and the other going through every cell of Sheet 2 Column A. I would then add an If/else statement, specifying that if example[x] - (x is a variable that is changed with each increment of the loop) were equal to the cell that the 2nd loop was currently on, it would then copy the entire row and paste it to sheet 1 of column L row x.
I have tried getting some background by recording a macro of me doing the basic steps for one search in excel, but when I look at the code and get to the find method, it will enter the specific value of the cell I'm trying to search and not a variable one. Ex. it will enter "XP_23414" in the find method instead of something like "Selection.paste" or something of the like, which would make the macro useful for only that specific case.
If it helps, the values that will be in Column K Sheet 1 and Column A Sheet 2 will be in this format "XP_12456" or something of the like, which would make me think of a "string" in java.
Any help is appreciated, as I am currently really lost. Taking on something like this without any prior foundation in vba was not a smart idea.
Thanks, and sorry for the wall of text
Jastro
New poster here, and I was hoping to get some help with a macro for Excel 2007. I have a working understanding of programming in Java and C++, but teaching myself how to write macros in Excel is apparently beyond me. I want to write a macro that would be able to
1. Take the contents of each cell in Column K of sheet 1 and search for it in Column A of sheet 2
2. If the value is found, copy the entire row that the value is found in and paste it back to sheet 1 , starting from column L of the same row as the cell that was initially searched for.
3. If the value is not found, move on to the next cell of Column K.
for example, the program should start with finding the contents of cell K1, searching for it in the entire Column A of Sheet 2, and if it is found in, lets say, row 3, the macro will copy the entire contents of row 3 and paste it to sheet 1, L1 and beyond (depending on how many cells were in the row). Then it will move on to K2 and perform the exact same actions.
If I were to approach this in Java, I would use nested loops, with one going through every cell of Sheet 1 Column K and the other going through every cell of Sheet 2 Column A. I would then add an If/else statement, specifying that if example[x] - (x is a variable that is changed with each increment of the loop) were equal to the cell that the 2nd loop was currently on, it would then copy the entire row and paste it to sheet 1 of column L row x.
I have tried getting some background by recording a macro of me doing the basic steps for one search in excel, but when I look at the code and get to the find method, it will enter the specific value of the cell I'm trying to search and not a variable one. Ex. it will enter "XP_23414" in the find method instead of something like "Selection.paste" or something of the like, which would make the macro useful for only that specific case.
If it helps, the values that will be in Column K Sheet 1 and Column A Sheet 2 will be in this format "XP_12456" or something of the like, which would make me think of a "string" in java.
Any help is appreciated, as I am currently really lost. Taking on something like this without any prior foundation in vba was not a smart idea.
Thanks, and sorry for the wall of text
Jastro