Makro to find selected value in another sheet, copy rows under found value and paste below previously selected cell

Marciboy

New Member
Joined
Dec 28, 2019
Messages
19
Office Version
  1. 365
Platform
  1. MacOS
Hello,

I need help with a makro in excel. I have got table1 in worksheet1 and on worksheet2 there is table2. Now, I want to select a certain value in table1, search for that value in table two and then copy the content below the found value and insert it under the selected value in table 1. Sometimes there is only one row that should be copied, then other times there are between 2 and 4 rows to be copied.

Table1
Sth.Sth.Sth.Sth.Value of interestSth.etc.etcetcetc
Insert hereInsert hereInsert hereInsert hereInsert hereInsert here


Table2
nothingnothingnothingnothingValue of interest
nothing
nothingnothingnothingnothing
nothingnothingnothingnothingValue to copy overValue to copy overValue to copy overValue to copy overValue to copy overValue to copy over
nothingnothingnothingnothingValue to copy overValue to copy overValue to copy overValue to copy overValue to copy overValue to copy over
nothingnothingnothingnothingValue to copy overValue to copy overValue to copy overValue to copy overValue to copy overValue to copy over
nothingnothingnothingnothingnothingnothingnothingnothingnothingnothing
Value that could be of interestnothingnothingnothingnothingnothing
Value that could be to copyetc.etc..........
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I have the following but i have troubles with pasting the copied data into the saved cell address from the beginning

VBA Code:
Sub copy_row()

Dim search As String
Dim pastle As Worksheet
Dim a As String

a = ActiveCell.Address


Set pastle = ActiveSheet
search = ActiveCell.Value

Sheets("Kalkulation").Select
Range("A26:A60").Select
    
    Selection.Find(What:=search, After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
        
    ActiveCell.Offset(1, 0).Select

If ActiveCell.Value = "ME406072" Or ActiveCell.Value = "ME530513" Then

    ActiveCell.Resize(1, 6).Select
    Range(Selection, Selection.End(xlDown)).copy

Else

    ActiveCell.Resize(1, 6).copy
    
    With pastle
        .Range("a").PasteSpecial paste:=xlPasteValues
    End With
    
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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