Excel VBA

M

Mr. Clean

I need to write a VBA program (or a macro) that will select a cell from a
worksheet, then look for the same text in a cell in another worksheet (in the
same workbook), then copy another cell in the row that the text is found,
then paste it in the first worksheet.
 
R

RandiBPD

Can someone please help me figure out how to start a new thread/question?
There is something I need urgent help with and I have tried for a very long
time. Yes, I am signed in. Yes, i press NEW and then general comment and
question and it does nothing. I would really appreciate your help.

By the way, is there any way to reduce the size of a document map? It is so
large and the type runs off and I can't use it that way.

THANKS.
 
O

Otto Moehrbach

How is the first cell selected? For instance, does the user select a cell
and then run the macro?
Where in the first sheet do you want the value placed that came from the
second sheet? HTH Otto
 
M

Mr. Clean

I'd like to start at the first row and step through each row of the first
sheet. The worksheet has 300 rows, so I'd like to automate the process.
The value should be at the end of the row selected.
 
O

Otto Moehrbach

This macro should do what you want. I assumed the following:
Your data starts in row 2 in Column A of the first sheet.
The copied data goes into Column G of the first sheet.
The second sheet is named "Second".
The code searches for the values in Column A of the first sheet.
The code searches IN Column A of the second sheet.
If found, the value in Column G of the second sheet is copied and pasted to
the first sheet.
HTH Otto
Sub CopyData()
Dim RngColAFirst As Range
Dim RngColASecond As Range
Dim i As Range
Set RngColAFirst = _
Range("A2", Range("A" & Rows.Count).End(xlUp))
With Sheets("Second")
Set RngColASecond = _
.Range("A2", .Range("A" & Rows.Count).End(xlUp))
For Each i In RngColAFirst
If Not RngColASecond.Find(What:=i.Value, _
LookAt:=xlWhole) Is Nothing Then
RngColASecond.Find(What:=i.Value, _
LookAt:=xlWhole).Offset(, 6).Copy _
i.Offset(, 6)
End If
Next i
End With
End Sub
 
Top