Loop through worksheets and copy rows

metanei7

New Member
Joined
Jun 21, 2018
Messages
8
Hello,

I am kind new on VBA so please be kind :D

I am trying to make a code that will loop through worksheets that have same name but different number exp Dataset 2(1), Dataset 2(2), Dataset 2(3).

Then i want to have another loop inside that loop that will look for the last row from column A and copy it on worksheets("Sheet1").
If the copied value has the same number on worksheets("sheet1") on column A, i want it to then add only the value from the column D which it was trying to copy from.

Anyone has any clue how to do it?

Regards,
Metanei
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hello,

Is anybody that can help me with this problem?
I have change the code on Sheet1 instead of sheet1 and now on it i get all the time Debug.Print rs.Name
I have no idea where that came from:D

<colgroup><col width="101"><col width="64"></colgroup><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
Still nothing is been pasted...i will try to find more help on this as i am not sure what is wrong

This part of the code does the pasting, only IF the value is found. It's important that the value is searching is the only value in the cell. Make sure no whitespace is there too.

Code:
[COLOR=#333333]           'if rFind is nothing then the value wasn't found
[/COLOR]            If rFind Is Nothing Then
                'Value not found so paste nothing IS THIS CORRECT?

            Else ' value was found
            
                'Copy the last row
                ws.Rows(lr).Copy
                
                [B]'Paste the copied row to the next blank row
                wsPaste.Range("A" & nb).PasteSpecial xlPasteAl[/B]l
                
                'next balnk row is +1
                nb = nb + 1 [COLOR=#333333]            End If[/COLOR]

How proficient are you with stepping through the code?. If you step through you will see what is happening at each line and what value is stored.

Try this and make sure it is behaving as planned.
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,572
Members
448,972
Latest member
Shantanu2024

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