Copy Data from one Sheet to another(find string and copy all Rows and Columns until Empty)

silentwolf

Well-known Member
Joined
May 14, 2008
Messages
1,216
Office Version
  1. 2016
Hi guys,

I would need some help please.

I like to find a particular string within a worksheet and copy all cells below and to the right of that cell to another worksheet but only till the row or column is empty.

So pasically find Art:Nr: and copy all data below and to the right until the row or column is empty and then find the next Art:Nr: and do the same...

Can someone help me with this issue please?

Art:NrVPEEinheitPrice
125210l12,99
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi again,

this code I got so far it is not quite working yet...
Was wondering if someone can give me a little help to complete this code..
VBA Code:
Sub TestCopy()
    Application.ScreenUpdating = False
    Dim i As Long
    
    Dim ans As String
    ans = "Art.-Nr."
    
    Dim Lastrow As Long
    Dim Lastrowb As Long
    Lastrow = Sheets("Abby_ScanN").Cells(Rows.Count, "A").End(xlUp).Row
    Lastrowb = Sheets("NewSheet").Cells(Rows.Count, "A").End(xlUp).Row + 1
    Sheets("Abby_ScanN").Activate
        For i = 1 To Lastrow
            If InStr(Sheets("Abby_ScanN").Cells(i, "A").Value, ans) Then
'                Debug.Print Cells(i, "A").Address
                Cells(i, "A").CurrentRegion.Copy Destination:=Sheets("NewSheet").Rows(Lastrowb)
                Lastrowb = Lastrowb + 1
            End If
        Next
    Application.ScreenUpdating = True
End Sub

How does this code need to change so it it findes again the last used row in column A from Lastrowb? Currently it override the values already paste into the NewSheet.

Thanks for your help!

Much appreciated..
 
Upvote 0
How about
VBA Code:
            If InStr(Sheets("Abby_ScanN").Cells(i, "A").Value, Ans) Then
'                Debug.Print Cells(i, "A").Address
                With Cells(i, "A").CurrentRegion
                     .Copy destination:=Sheets("NewSheet").Rows(Lastrowb)
                     Lastrowb = Lastrowb + .Rows.Count
                End With
            End If
 
Upvote 0
Solution
How about
VBA Code:
            If InStr(Sheets("Abby_ScanN").Cells(i, "A").Value, Ans) Then
'                Debug.Print Cells(i, "A").Address
                With Cells(i, "A").CurrentRegion
                     .Copy destination:=Sheets("NewSheet").Rows(Lastrowb)
                     Lastrowb = Lastrowb + .Rows.Count
                End With
            End If
Hi Fluff,

thank you for your help!
It is getting closer..
Two questions what if I like to exact word?
And also at the moment it copies some date accross the hole NewSheet...

Somewhere is still a problem but I can not figure it out unfortunatelly where the issue is...

Thank you!!
 
Upvote 0
If you want an exact match use
VBA Code:
If Sheets("Abby_ScanN").Cells(i, "A").Value = Ans Then
 
Upvote 0
Thank you very much Fluff.
Copy is still not quite working but I will look into it more...

Cheers
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,443
Members
448,898
Latest member
drewmorgan128

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