try this its working fine i tested it again add \ at teh edn of folder path C:\Users\ashishkoul\Desktop\Sample files 1 june 2014\students\
Sub merge_data() Dim filenm As String, folderpath As String folderpath = "C:\Users\ashishkoul\Desktop\Sample files 1 june 2014\students\" ' change folder here filenm = Dir(folderpath) Application.DisplayAlerts = False Application.ScreenUpdating = False While (filenm <> "") If InStr(filenm, ".xls") > 0 Then ' open only excel workbooks ' if found display full path in message box If UCase(filenm) <> UCase("master_file.xlsm") Then Call copy_data(folderpath & filenm) ' change master file name here End If filenm = Dir Wend Application.CutCopyMode = False Application.DisplayAlerts = True Application.ScreenUpdating = True Range("a1").Select End Sub Sub copy_data(filename As String) Dim wkb As Workbook Dim i As Long Set wkb = Workbooks.Open(filename) i = ThisWorkbook.Sheets(1).Range("xfd1").End(xlToLeft).Column + 1 ThisWorkbook.Sheets(1).Cells(1, i).Value = Left(wkb.Name, InStr(wkb.Name, ".") - 1) wkb.Sheets(1).Range("J6:j9").Copy Destination:=ThisWorkbook.Sheets(1).Cells(2, i) wkb.Close , False End Sub On Sun, Jun 1, 2014 at 12:36 PM, ashish koul <koul.ash...@gmail.com> wrote: > ok wait 2 min > > > On Sun, Jun 1, 2014 at 12:34 PM, Michael Lovin <mwlo...@gmail.com> wrote: > >> office 2010 >> >> >> On Sunday, June 1, 2014 2:53:01 PM UTC+8, ashish wrote: >> >>> are you using 2003 >>> >>> >>> >>> On Sun, Jun 1, 2014 at 12:18 PM, Michael Lovin <mwl...@gmail.com> wrote: >>> >>>> Well....it appears that it is doing something. (i see as if files open >>>> but just for a second) .but still not populating the master_file...I >>>> renamed to master_file1...and place in the same directory as my student >>>> files.....because of a prompt that your file was "read only"....... (idid >>>> notice that file was populated already form the 3 student data so I >>>> deleted it and save the file again then rand the VB again... it did not >>>> populate.. hard to understand why this is not working... >>>> The code looks similar to the old code.... ...but still not >>>> working....I did change the path to ... >>>> >>>> Sub merge_data() >>>> Dim filenm As String, folderpath As String >>>> folderpath = "C:\Users\Michael\Desktop\ESL_ >>>> Consulting\Students\Student_Test\" ' change folder here >>>> filenm = Dir(folderpath) >>>> Application.DisplayAlerts = False >>>> Application.ScreenUpdating = False >>>> While (filenm <> "") >>>> If InStr(filenm, ".xls") > 0 Then ' open only excel workbooks >>>> ' if found display full path in message box >>>> Call copy_data(folderpath & filenm) >>>> End If >>>> filenm = Dir >>>> Wend >>>> Application.CutCopyMode = False >>>> Application.DisplayAlerts = True >>>> Application.ScreenUpdating = True >>>> Range("a1").Select >>>> End Sub >>>> >>>> Sub copy_data(filename As String) >>>> Dim wkb As Workbook >>>> Dim i As Long >>>> Set wkb = Workbooks.Open(filename) >>>> >>>> i = ThisWorkbook.Sheets(1).Range("xfd1").End(xlToLeft).Column + 1 >>>> ThisWorkbook.Sheets(1).Cells(1, i).Value = Left(wkb.Name, >>>> InStr(wkb.Name, ".") - 1) >>>> wkb.Sheets(1).Range("J6:j9").Copy >>>> Destination:=ThisWorkbook.Sheets(1).Cells(2, >>>> i) >>>> >>>> wkb.Close , False >>>> >>>> End Sub >>>> >>>> >>>> On Sunday, June 1, 2014 11:55:15 AM UTC+8, Michael Lovin wrote: >>>>> >>>>> I am sure this has been asked many times but I cannot find a thread >>>>> that answers my questions..... I have code (pasted below) but it does >>>>> not >>>>> work and it does not error....(no highlight or pop up error message) >>>>> >>>>> I have several workbooks with sequential file names..student1, >>>>> student2, etc. .In each workbook first sheet (Sheet1) there is a coloum >>>>> with data (J6:J9) .. Each row is a different label ie Gammar, >>>>> Vocabulary, >>>>> etc >>>>> I want to sequence through the workbooks, copy the data at (J6:J9) and >>>>> paste it into master workbook, in a rows with the colum as the titles >>>>> ...so >>>>> under A coloum the J6:J9 data is pasted into A1, A2,,A3, etc in sequence >>>>> for all the student workbooks. >>>>> I hope I explained that clearly... here is the code so far...but not >>>>> working and no error pop up.... >>>>> >>>>> Sub LoopThroughDirectory() >>>>> Dim MyFile As String >>>>> Dim erow >>>>> Dim Filepath As String >>>>> MyFile = Dir("C:\Users\Michael\Desktop\ESL_Consulting\Students\Studen >>>>> t_Test\)") >>>>> >>>>> Do While Len(MyFile) > 0 >>>>> If MyFile = "Student_Master.xlsm" Then >>>>> Exit Sub >>>>> End If >>>>> Workbooks.Open (Filepath & MyFile) >>>>> Range("J6:J9").Copy >>>>> ActiveWorkbook.Close >>>>> erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row >>>>> ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range(Cells(erow, >>>>> 1), Cells(erow, 4)) >>>>> >>>>> MyFile = Dir >>>>> Loop >>>>> End Sub >>>>> >>>>> -- >>>> Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? >>>> It’s =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ >>>> https://www.facebook.com/discussexcel >>>> >>>> FORUM RULES >>>> >>>> 1) Use concise, accurate thread titles. Poor thread titles, like Please >>>> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice >>>> will not get quick attention or may not be answered. >>>> 2) Don't post a question in the thread of another member. >>>> 3) Don't post questions regarding breaking or bypassing any security >>>> measure. >>>> 4) Acknowledge the responses you receive, good or bad. >>>> 5) Jobs posting is not allowed. >>>> 6) Sharing copyrighted material and their links is not allowed. >>>> >>>> NOTE : Don't ever post confidential data in a workbook. Forum owners >>>> and members are not responsible for any loss. >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "MS EXCEL AND VBA MACROS" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to excel-macros...@googlegroups.com. >>>> To post to this group, send email to excel-...@googlegroups.com. >>>> >>>> Visit this group at http://groups.google.com/group/excel-macros. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> >>> >>> -- >>> *Regards* >>> >>> *Ashish Koul* >>> >>> >>> *Visit* >>> http://www.excelvbamacros.in >>> Like Us on Facebook <https://www.facebook.com/excelvbacodes> >>> Join Us on Facebook <http://www.facebook.com/groups/163491717053198/> >>> >>> >>> P Before printing, think about the environment. >>> >>> >>> >> -- >> Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s >> =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ >> https://www.facebook.com/discussexcel >> >> FORUM RULES >> >> 1) Use concise, accurate thread titles. Poor thread titles, like Please >> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice >> will not get quick attention or may not be answered. >> 2) Don't post a question in the thread of another member. >> 3) Don't post questions regarding breaking or bypassing any security >> measure. >> 4) Acknowledge the responses you receive, good or bad. >> 5) Jobs posting is not allowed. >> 6) Sharing copyrighted material and their links is not allowed. >> >> NOTE : Don't ever post confidential data in a workbook. Forum owners and >> members are not responsible for any loss. >> --- >> You received this message because you are subscribed to the Google Groups >> "MS EXCEL AND VBA MACROS" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to excel-macros+unsubscr...@googlegroups.com. >> To post to this group, send email to excel-macros@googlegroups.com. >> Visit this group at http://groups.google.com/group/excel-macros. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > *Regards* > > *Ashish Koul* > > > *Visit* > http://www.excelvbamacros.in > Like Us on Facebook <https://www.facebook.com/excelvbacodes> > Join Us on Facebook <http://www.facebook.com/groups/163491717053198/> > > > P Before printing, think about the environment. > > > -- *Regards* *Ashish Koul* *Visit* http://www.excelvbamacros.in Like Us on Facebook <https://www.facebook.com/excelvbacodes> Join Us on Facebook <http://www.facebook.com/groups/163491717053198/> P Before printing, think about the environment. -- Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ https://www.facebook.com/discussexcel FORUM RULES 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Jobs posting is not allowed. 6) Sharing copyrighted material and their links is not allowed. NOTE : Don't ever post confidential data in a workbook. Forum owners and members are not responsible for any loss. --- You received this message because you are subscribed to the Google Groups "MS EXCEL AND VBA MACROS" group. To unsubscribe from this group and stop receiving emails from it, send an email to excel-macros+unsubscr...@googlegroups.com. To post to this group, send email to excel-macros@googlegroups.com. Visit this group at http://groups.google.com/group/excel-macros. For more options, visit https://groups.google.com/d/optout.