Macro to search value on sheet1 in sheet2, copy the line and paste it sheet1 as result

Ulisses_Carso

New Member
Joined
Sep 4, 2020
Messages
39
Office Version
  1. 365
Platform
  1. Windows
First i would like say that i've spent four hours searching for a solution to my problem in some forums with no sucess.

Here is the thing:
Every week i have to copy a range of lines generated from a dinamic sheet wich have X lines and almost 35 columns, this data is in Sheet "BaseDin". In another Sheet "Base" i have X line in one column.

Whats i need is:
A Macro to search the column on sheet "Base" in sheet "BaseDin", copy the line but only the range "A2:AF2" for example, get this range and paste it on sheet "Base" in the same line and range fo the searched cell.

The problem is:
This is a very tiring process (more than 150 lines), i have to automate this part of the task to save time, he problem is that i don't have the knowledge with VBA to create this Macro, so if anyone help me with i'll be very very grateful.

Note: I don't have a Macro to post here as first step because my attempts to do so were a failure.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Copy and paste this to code module1. The code assumes that the key search data is located in column A of both sheets. If not, the code fails.

VBA Code:
Sub t()
Dim sh1 As Worksheet, sh2 As Worksheet, c As Range, fn As Range
Set sh1 = Sheets("BaseDin")
Set sh2 = Sheets("Base")
    With sh2
        For Each c In .Range("A2", .Cells(Rows.Count, 1).End(xlUp))
            Set fn = sh1.Range("A:A").Find(c.Value, , xlValues, xlWhole)
            If Not fn Is Nothing Then
                fn.Offset(, 1).Resize(, 5).Copy c.Offset(, 1)
            End If
        Next
    End With
End Sub
 
Upvote 0
Hello JLGWhiz

it worked perfectly, I made some adjustments to adapt to my data but it worked, you really helped me a lot, I am very grateful to you.
I only have one doubt, there is a way to select a specific range for each cell? for example:

my idea is c. The offset starts at 3, so column A remains the main search, column B the search range for each value in column A

column A column B
value 1 cell a2: j2
value 2 cell b3: b12
value 3 cell c6: c21
and goes until first blank ...

i don't know if it's possible, never tried to do it
 
Upvote 0
I am not following your logic in the example, but it is beyond the scope of the original topic in this thread and should be started as a new thread anyway. Generally speaking, anything you can do manually can be done with vba code. The code is nothing more than instructions to the CPU and compiler on which commands and what order to execute. Nothing magical about it.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top