1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| Sub Open_MW()
Dim MW_number As Variant
Dim wb2 As Workbook
Dim ligne As Long
Dim message As String, Answer As Variant
ligne = Range("A1").End(xlDown).Row + 1
MW_number = InputBox("Please enter the MW number:")
'look if the MW is already in the database
With Sheets("Database_MW").Range("A1:A10000")
Set c = .find(what:=MW, After:=Range("A2"), LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False)
If c Is Nothing Then 'if the margin worksheet is not in the database
Set wb2 = Workbooks.Open("C:\Users\Jules.Matuvu\Desktop\temp file\MW" & MW_number) '& ".xls"
Windows("MW" & MW_number & ".xlsx").Activate
Range("B2:B7").Select
Selection.Copy
Windows("New project.xlsm").Activate
Sheets("Database_MW").Cells(ligne, 1).Activate
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Windows("MW" & MW_number & ".xlsx").Activate
Range("B11:B15").Select
Selection.Copy
Windows("New project.xlsm").Activate
Sheets("Database_MW").Cells(ligne, 7).Activate
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Else
message = "MW is already in the database, do you still want to put it?"
Answer = MsgBox(message, vbYesNo)
Select Case Answer 'two choices, do you still want to upload the information
Case vbYes 'if yes, it opens and copy paste
Set wb2 = Workbooks.Open("C:\Users\Jules.Matuvu\Desktop\temp file\MW" & MW_number) '& ".xls"
Windows("MW" & MW_number & ".xlsx").Activate
Range("B2:B7").Select
Selection.Copy
Windows("New project.xlsm").Activate
Sheets("Database_MW").Cells(ligne, 1).Activate
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Windows("MW" & MW_number & ".xlsx").Activate
Range("B11:B15").Select
Selection.Copy
Windows("New project.xlsm").Activate
Sheets("Database_MW").Cells(ligne, 7).Activate
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Case vbNo 'if not, it exit sub
Exit Sub
End Select
End If
End With
End Sub |
Partager