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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
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
[TABLE="width: 165"]
<colgroup><col width="101"><col width="64"></colgroup><tbody>[TR]
[TD="class: xl66, width: 101"]I have no idea where that came from:D
[/TD]
[TD="class: xl66, width: 64"][/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 165"]
<tbody>[TR]
[TD="class: xl64, width: 101"][/TD]
[TD="class: xl64, width: 64"][/TD]
[/TR]
</tbody>[/TABLE]
 
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,223,911
Messages
6,175,333
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