Hi,
Kindly help me find the reason why this code is giving me run time error 5.
When I select the first case to the third case the code works fine, but whenever I am going to return to 1st case or select 2nd case from 3rd case the run time error appears and highlights this part of the code.
Can you please help me understand why?
Thanks,
HYKE
kindly forgive my codes, I am just not really into VBA..
Kindly help me find the reason why this code is giving me run time error 5.
Code:
Private Sub Oft_Change()
Dim prodName As Range
Dim mobProd As Range
Dim emProd As Range
Dim ws As Worksheet
Set ws = Worksheets("LookupLists")
Select Case Oft
Case "BPME"
'Worksheets("CONSOLIDATED").Select
Me.Spreadsheet1.Sheets("Sheet1").Range("A1:AJ10").Value = Worksheets("BPME").Range("A1:AJ10").Value
Me.Spreadsheet1.Sheets("Sheet1").Activate
Me.Spreadsheet1.Sheets("Sheet1").Name = "BPME"
Worksheets("BPME").Select
Me.cProd.Visible = True
Me.moProdbox.Visible = False
Me.emProdbox.Visible = False
For Each prodName In ws.Range("prodName")
With Me.cProd
.AddItem prodName.Value
.List(.ListCount - 1, 1) = prodName.Offset(0, 1).Value
End With
Next prodName
Case "EXXON MOBIL"
Me.Spreadsheet1.Sheets("Sheet2").Range("A1:AJ10").Value = Worksheets("EXXONMOBIL").Range("A1:AJ10").Value
Me.Spreadsheet1.Sheets("Sheet2").Activate
Me.Spreadsheet1.Sheets("Sheet2").Name = "EXXONMOBIL"
Worksheets("EXXONMOBIL").Select
Me.cProd.Visible = False
Me.moProdbox.Visible = True
Me.emProdbox.Visible = False
For Each mobProd In ws.Range("mobProd")
With Me.moProdbox
.AddItem mobProd.Value
.List(.ListCount - 1, 1) = mobProd.Offset(0, 1).Value
End With
Next mobProd
Case "EMARAT"
Me.Spreadsheet1.Sheets("Sheet3").Range("A1:AJ10").Value = Worksheets("EMARAT").Range("A1:AJ10").Value
Me.Spreadsheet1.Sheets("Sheet3").Activate
Me.Spreadsheet1.Sheets("Sheet3").Name = "EMARAT"
Worksheets("EMARAT").Select
Me.cProd.Visible = False
Me.moProdbox.Visible = False
Me.emProdbox.Visible = True
For Each emProd In ws.Range("emProd")
With Me.emProdbox
.AddItem emProd.Value
.List(.ListCount - 1, 1) = emProd.Offset(0, 1).Value
End With
Next emProd
End Select
End Sub
When I select the first case to the third case the code works fine, but whenever I am going to return to 1st case or select 2nd case from 3rd case the run time error appears and highlights this part of the code.
Code:
Me.Spreadsheet1.Sheets("Sheet1").Range("A1:AJ10").Value = Worksheets("BPME").Range("A1:AJ10").Value
Can you please help me understand why?
Thanks,
HYKE
kindly forgive my codes, I am just not really into VBA..