Hello,
I'm a new user of VBA and have run into a problem with the (poorly) written code I have made.
I have tried to shorten my code by combining common tasks, however it runs but selects the wrong data
In the example below,
The code returns the expected if I select "M135X" and "300 hrs", but unexpected results if "M135X" and "1500 hrs" is selected
My variables are models and hours - the code below is for one model.
Any assistance would be greatly appreciated
I'm a new user of VBA and have run into a problem with the (poorly) written code I have made.
I have tried to shorten my code by combining common tasks, however it runs but selects the wrong data
In the example below,
The code returns the expected if I select "M135X" and "300 hrs", but unexpected results if "M135X" and "1500 hrs" is selected
My variables are models and hours - the code below is for one model.
Any assistance would be greatly appreciated
Code:
'Next Model
ElseIf Range("D3") = "M135X" And Range("E3") = "1st Service" Then
ThisWorkbook.Worksheets("M100X-135X").Range("B37:D44").Copy
Range("J10").Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
ThisWorkbook.Worksheets("Picking Lists").Range("B36:E41").Copy
Range("Q10").Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
ElseIf Range("D3") = "M135X" And Range("E3") = "300 hrs" Or Range("E3") = "1500 hrs" Or Range("E3") = "2100 hrs" Then
ThisWorkbook.Worksheets("M100X-135X").Range("Z37:AB43").Copy
Range("J10").Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
ThisWorkbook.Worksheets("M100X-135X").Range("B47:D50").Copy
Range("H20").Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
ThisWorkbook.Worksheets("Picking Lists").Range("N36:Q41").Copy
Range("Q10").Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
ElseIf Range("D3") = "M135X" And Range("E3") = "600 hrs" Or Range("E3") = "1200 hrs" Or Range("E3") = "2400 hrs" Or Range("E3") = "3000 hrs" Then
ThisWorkbook.Worksheets("M100X-135X").Range("AL37:AN45").Copy
Range("J10").Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
ThisWorkbook.Worksheets("M100X-135X").Range("B47:D50").Copy
Range("H20").Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
ThisWorkbook.Worksheets("Picking Lists").Range("V36:Y41").Copy
Range("Q10").Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
ElseIf Range("D3") = "M135X" And Range("E3") = "900 hrs" Or Range("E3") = "1800 hrs" Or Range("E3") = "2700 hrs" Then
ThisWorkbook.Worksheets("M100X-135X").Range("Z37:AB43").Copy
Range("J10").Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
ThisWorkbook.Worksheets("M100X-135X").Range("B47:D50").Copy
Range("H20").Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
ThisWorkbook.Worksheets("Picking Lists").Range("N36:Q41").Copy
Range("Q10").Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
'Next Model
Last edited by a moderator: