james912375
New Member
- Joined
- Jun 9, 2011
- Messages
- 15
Hi,
i am new VB and im trying upgrade an excel data compiling sheet.
i have written code to import 2 separate .txt files save them into hidden sheets and then and then move both of those sheets into one premade calculation sheets.
This works fine but i need to be able to change the files in the file path automatically so i can save new files in there and and when the macro is run the new values show up. This also seems to be hard beacuse i cant figure out how import these without a name on them so i have to input the original name into the code which obviously then wont allow me to change the file.. Please help!!!! i will highlight the parts of my code i think may need to be changed.. Thanks in advance!!
Dim master, master1 As Workbook
Set master = Workbooks.Open("C:\Documents and Settings\hodsonj\My Documents\txt files fwd\PARFWD.txt")
'i need the above to use any .txt files in the txt files fwd directory
counter = 3
Do Until ThisWorkbook.Sheets("Sheet1").Cells(counter, 1).Value = ""
counter = counter + 1
Loop
mastercounter = 3
Do Until master.Sheets("PARFWD").Cells(mastercounter, 1).Value = "" 'i need the above reference the same as above & so on
ThisWorkbook.Sheets("Sheet1").Range(counter & ":" & counter).Value = master.Sheets("PARFWD").Range(mastercounter & ":" & mastercounter).Value
counter = counter + 1
mastercounter = mastercounter + 1
Loop
Set master1 = Workbooks.Open("C:\Documents and Settings\hodsonj\My Documents\txt files aft\PARAFT.txt")
counter = 3
Do Until ThisWorkbook.Sheets("Sheet2").Cells(counter, 1).Value = ""
counter = counter + 1
Loop
mastercounter = 3
Do Until master1.Sheets("PARAFT").Cells(mastercounter, 1).Value = ""
ThisWorkbook.Sheets("Sheet2").Range(counter & ":" & counter).Value = master1.Sheets("PARAFT").Range(mastercounter & ":" & mastercounter).Value
counter = counter + 1
mastercounter = mastercounter + 1
Loop
master.Close
master1.Close
Dim counter1 As Integer
counter1 = 3
Do Until ThisWorkbook.Sheets("Sheet1").Cells(counter1, 1).Value = ""
ThisWorkbook.Sheets("SINS Comp Raw Data").Range("A" & counter1, "O" & counter1).Value = ThisWorkbook.Sheets("Sheet1").Range("A" & counter1, "O" & counter1).Value
ThisWorkbook.Sheets("Sheet1").Range("A" & counter1, "O" & counter1).Value = ""
counter1 = counter1 + 1
Loop
Dim counter2 As Integer
counter2 = 3
Do Until ThisWorkbook.Sheets("Sheet2").Cells(counter2, 1).Value = ""
ThisWorkbook.Sheets("SINS Comp Raw Data").Range("Q" & counter2, "AE" & counter2).Value = ThisWorkbook.Sheets("Sheet2").Range("A" & counter2, "O" & counter2).Value
ThisWorkbook.Sheets("Sheet2").Range("A" & counter2, "O" & counter2).Value = ""
counter2 = counter2 + 1
Loop
End Sub
Thanks so much!!!
i am new VB and im trying upgrade an excel data compiling sheet.
i have written code to import 2 separate .txt files save them into hidden sheets and then and then move both of those sheets into one premade calculation sheets.
This works fine but i need to be able to change the files in the file path automatically so i can save new files in there and and when the macro is run the new values show up. This also seems to be hard beacuse i cant figure out how import these without a name on them so i have to input the original name into the code which obviously then wont allow me to change the file.. Please help!!!! i will highlight the parts of my code i think may need to be changed.. Thanks in advance!!
Dim master, master1 As Workbook
Set master = Workbooks.Open("C:\Documents and Settings\hodsonj\My Documents\txt files fwd\PARFWD.txt")
'i need the above to use any .txt files in the txt files fwd directory
counter = 3
Do Until ThisWorkbook.Sheets("Sheet1").Cells(counter, 1).Value = ""
counter = counter + 1
Loop
mastercounter = 3
Do Until master.Sheets("PARFWD").Cells(mastercounter, 1).Value = "" 'i need the above reference the same as above & so on
ThisWorkbook.Sheets("Sheet1").Range(counter & ":" & counter).Value = master.Sheets("PARFWD").Range(mastercounter & ":" & mastercounter).Value
counter = counter + 1
mastercounter = mastercounter + 1
Loop
Set master1 = Workbooks.Open("C:\Documents and Settings\hodsonj\My Documents\txt files aft\PARAFT.txt")
counter = 3
Do Until ThisWorkbook.Sheets("Sheet2").Cells(counter, 1).Value = ""
counter = counter + 1
Loop
mastercounter = 3
Do Until master1.Sheets("PARAFT").Cells(mastercounter, 1).Value = ""
ThisWorkbook.Sheets("Sheet2").Range(counter & ":" & counter).Value = master1.Sheets("PARAFT").Range(mastercounter & ":" & mastercounter).Value
counter = counter + 1
mastercounter = mastercounter + 1
Loop
master.Close
master1.Close
Dim counter1 As Integer
counter1 = 3
Do Until ThisWorkbook.Sheets("Sheet1").Cells(counter1, 1).Value = ""
ThisWorkbook.Sheets("SINS Comp Raw Data").Range("A" & counter1, "O" & counter1).Value = ThisWorkbook.Sheets("Sheet1").Range("A" & counter1, "O" & counter1).Value
ThisWorkbook.Sheets("Sheet1").Range("A" & counter1, "O" & counter1).Value = ""
counter1 = counter1 + 1
Loop
Dim counter2 As Integer
counter2 = 3
Do Until ThisWorkbook.Sheets("Sheet2").Cells(counter2, 1).Value = ""
ThisWorkbook.Sheets("SINS Comp Raw Data").Range("Q" & counter2, "AE" & counter2).Value = ThisWorkbook.Sheets("Sheet2").Range("A" & counter2, "O" & counter2).Value
ThisWorkbook.Sheets("Sheet2").Range("A" & counter2, "O" & counter2).Value = ""
counter2 = counter2 + 1
Loop
End Sub