• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Do While loop

Ashhu

Active Member
I have code which copy data from .XLS sheets from selected folder and paste in Active sheet.
Problem: when i run code its copying same data twice. See and run macro.
Please help.

Attachment:
Code avbl in this sheet. and also sample test sheet.
Please help
 

Attachments

  • Code.xlsm
    22.1 KB · Views: 8
  • Sample.xlsx
    9.1 KB · Views: 6
To add to above, it runs in F8 mode properly but not in F5 mode.
I'd be surprised!
Lines such as:
Code:
            For Each wks In wbk.Worksheets
            Set wks = Sheets("All Levels")
are likely to cause problems; if the workbook has 2 sheets, perhaps it will iterate twice, each time wks being reset to Sheets("All Levels").
What was the intent behind the line:
Set wks = Sheets("All Levels")
?
 
I'd be surprised!
Lines such as:
Code:
            For Each wks In wbk.WorksheetsThe
I'd be surprised!
Lines such as:
Code:
            For Each wks In wbk.Worksheets
            Set wks = Sheets("All Levels")
are likely to cause problems; if the workbook has 2 sheets, perhaps it will iterate twice, each time wks being reset to Sheets("All Levels").
What was the intent behind the line:
Set wks = Sheets("All Levels")
?
Thanks for the reply Pascal
Original search workbook have multiple sheets , i need code to search only in sheet named " All Levels".

I tried with "Set rFound = wks.UsedRange.Find(strSearch)" which will search in all sheets and all cells. i got same result.



In F8 step by step run it works most of the time but not in F5 mode.
I am fairly new to VBA excel. so not able to understand where its going wrong.
 
try changing:
Set wks = Sheets("All Levels")
to:
If wks.Name = "All Levels" Then

and adding:
End If
directly before the line:
Next
 
Back
Top