code run step by step but not in run time

vijaybhatt

New Member
Joined
Dec 23, 2015
Messages
17
Sub OpenFiles()






Dim ws As Worksheet
Dim MyFolder1 As String
Dim MyFile1 As String
Dim MyFolder2 As String
Dim MyFile2 As String
Dim i As Integer
ThisWorkbook.Sheets("CHE Inventory data").Activate


Range("A3", Range("A3").End(xlDown)).Select
Range(Selection, Selection.Offset(0, 25)).Select


Selection.ClearContents
Sheets("ADR").Select
Range("A3", Range("A3").End(xlDown)).Select
Range(Selection, Selection.Offset(0, 10)).Select
Selection.ClearContents




MyFolder = "Z:\MCT\Vijay\CHE Data\CHE Summary Data"


myfile = Dir(MyFolder & "\*.xls")
Workbooks.Open Filename:=MyFolder & "\" & myfile, _
Password:="**indiamissioncontrolteam2012***"
myfile = Dir
For i = 1 To Sheets.Count
Windows("CHE Summary data.xlsx").Activate
Sheets(i).Activate
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy


ThisWorkbook.Sheets(i).Activate
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues




Next
MsgBox "OK"
'Application.CutCopyMode = False
'Windows("CHE Summary data.xlsx").Close




Application.CutCopyMode = True
'STEP1lookupbsoUSER.STEP1lookupbsoUSER
End Sub




this code is not run when i click on run button but when i do f8 step by step its work perfect help me please
 

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.
First times its copy whatever I want but second tims its not running. But when I do step by step using f8 its run perfectly
 
Upvote 0
No there is no err Imran. its wroking fine when i debug it with F8 but when i run its coping only 1 time not my second sheet
 
Upvote 0
Thisworkbook is the workbook that contains the code so when you open another book to work on you need to refer to activeworkbook not this workbook.
 
Upvote 0
Thisworkbook is the workbook that contains the code so when you open another book to work on you need to refer to activeworkbook not this workbook.


its not copying data from sheet 2. while first time when sheet 1 data paste perfect.
 
Upvote 0
i have tried to change with the name of the workbook also but still same issue can u please work with this code and do some changes for need full.
 
Upvote 0
I would still try forgetting thisworkbook and thatworkbook.

use the workbook name and then there is no room for error and the macro knows exactly what it is doing
 
Upvote 0
I have tried change workbook name. But still only 1 sheet copy. And second sheet is not copying. But wjen I do f8 step by step its not working for sexond sheet
 
Upvote 0

Forum statistics

Threads
1,215,541
Messages
6,125,413
Members
449,223
Latest member
Narrian

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