MalumMorale
New Member
- Joined
- May 28, 2019
- Messages
- 6
Hey everyone,
this is my first post here since I'm new to VBA. I'm not good at coding but I will provide you with all the information I have right now.
Summary:
My goal --> Macro Step 2:
Trying to create a macro to consolidate data from multiple workbooks / Suppliers into one Master-File. This, first, Master-File edition will be used from a small amount of people to get data from their co-workers. They all will then give access to their master file to the same person, a new one . This person will use a new Master-File / Supermaster (Step 2) to consolidate the data from the original Master-Files. There's going to be another Step (3), which is basically going to be the same as in Step 2 but my current goal is to get to Step 2.
To clarify:
The data copied in Step1 is saved in the Suppliers Sheet2 ("Summen"), the copying starts at row 5 since there are headers in row 4. The macro for Step 1 is supposed to copy the supplier files data into Sheet1 ("AP-ProjektSumme"), starting at row 13 (12 is for headers).
What I did:
Access the new Master Sheet and change the copy range to Range(Cells(13, 1), Cells(lastRow, 17)).Copy
My problem:
When I edit and try to use the code from below for the requirements from Step 2 the copied data is messed up. What happens is that the data is copied correct until a specific column appears. The data then is shifted to the left and thereby not matching the header anymore. Which is kind of weird since the excel sheet itself has the same template structure. Also the headers are being copied and added to the last row copied even though it's not even in my specified copy range. I don't know if the copying itself or the pasting is the problem.
So what's happening doesn't make much sense to me...
The code attached is working for Step 1, but not Step 2 somehow.
Code for Step 1:
BTW pls ignore the system seperator change, it has nothing to do with the problem itself, just with the data I'm copying.
Please let me know if you need more information or have a another, better or easier approach for my task and problem!
I'll be looking forward for your responses since I've already read a few posts in this forum and I've seen that there are a lot of clever persons here!
- Stephan
this is my first post here since I'm new to VBA. I'm not good at coding but I will provide you with all the information I have right now.
Summary:
My goal --> Macro Step 2:
Trying to create a macro to consolidate data from multiple workbooks / Suppliers into one Master-File. This, first, Master-File edition will be used from a small amount of people to get data from their co-workers. They all will then give access to their master file to the same person, a new one . This person will use a new Master-File / Supermaster (Step 2) to consolidate the data from the original Master-Files. There's going to be another Step (3), which is basically going to be the same as in Step 2 but my current goal is to get to Step 2.
To clarify:
The data copied in Step1 is saved in the Suppliers Sheet2 ("Summen"), the copying starts at row 5 since there are headers in row 4. The macro for Step 1 is supposed to copy the supplier files data into Sheet1 ("AP-ProjektSumme"), starting at row 13 (12 is for headers).
What I did:
Access the new Master Sheet and change the copy range to Range(Cells(13, 1), Cells(lastRow, 17)).Copy
My problem:
When I edit and try to use the code from below for the requirements from Step 2 the copied data is messed up. What happens is that the data is copied correct until a specific column appears. The data then is shifted to the left and thereby not matching the header anymore. Which is kind of weird since the excel sheet itself has the same template structure. Also the headers are being copied and added to the last row copied even though it's not even in my specified copy range. I don't know if the copying itself or the pasting is the problem.
So what's happening doesn't make much sense to me...
The code attached is working for Step 1, but not Step 2 somehow.
Code for Step 1:
Code:
Private Sub copyDataMultipleWorkbooksIntoMaster()
'to change excels decimal separator from "," to "."
'converts numbers into the right format
With Application
.DecimalSeparator = "."
.UseSystemSeparators = False
End With
Dim folderPath As String, filePath As String, fileName As String
folderPath = "C:\Users\SXY\Desktop\Task\Programm\Cluster 1\Suppliers\"
'don't forget the backslash at the path end!
filePath = folderPath & "*.xls*"
'xlsm, xlsx, xls* etc. files are copyable
fileName = Dir(filePath)
Dim lastRow As Long, lastColumn As Long
Do While fileName <> ""
Workbooks.Open (folderPath & fileName)
lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
lastColumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
Worksheets("Summen").Activate
Range(Cells(5, 1), Cells(lastRow, 17)).Copy
'Range(Cells(5, 1): 4th row is for headers, therefore start at row 5
Application.DisplayAlerts = False
'Optional: activate Notifications ("Your Clipboard has a large amount of data, would you like to paste that, yes or no?")
ActiveWorkbook.Close
emptyRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
'to find next emptyRow
ActiveSheet.Paste Destination:=Worksheets("AP-ProjektSumme").Range(Cells(emptyRow, 1), Cells(emptyRow, 17))
'pasting the data into the master file
fileName = Dir
Loop
'reset system separator to ","
With Application
.DecimalSeparator = ","
.UseSystemSeparators = True
End With
End Sub
BTW pls ignore the system seperator change, it has nothing to do with the problem itself, just with the data I'm copying.
Please let me know if you need more information or have a another, better or easier approach for my task and problem!
I'll be looking forward for your responses since I've already read a few posts in this forum and I've seen that there are a lot of clever persons here!
- Stephan