i need help with this if statement.
i want excel to look at what text is in the combo box on my user form, depending on what it is i want it to move me to another workbook and a specific sheet within that workbook.
the code i have tried myself is...
Code:Sub CommandButton1_Click() If ComboBox1 = "Old Trafford Tour(Manchester)" Then GoTo_Workbook("Bookings").Worksheets("Trip 1").Range ("A1") Else If ComboBox1 = "Sister Act(London)" Then GoTo_Workbook("Bookings").Worksheets("Trip 2").Range ("A1") Else If ComboBox1 = "The Lion King(London)" Then GoTo_Workbook("Bookings").Worksheets("Trip 3").Range ("A1") Else If ComboBox1 = "Christmas Shopping(London)" Then GoTo_Workbook("Bookings").Worksheets("Trip 4").Range ("A1") Else If ComboBox1 = "Edinburgh Festival(Edinburgh)" Then GoTo_Workbook("Bookings").Worksheets("Trip 5").Range ("A1") Else If ComboBox1 = "The Gadget Show Live(Birmingham)" Then GoTo_Workbook("Bookings").Worksheets("Trip 6").Range ("A1") Else If ComboBox1 = "Disneyland Paris(Paris)" Then GoTo_Workbook("Bookings").Worksheets("Trip 7").Range ("A1") Else If ComboBox1 = "Port Aventura(Barcelona)" Then GoTo_Workbook("Bookings").Worksheets("Trip 8").Range ("A1") Else If ComboBox1 = "Booze Crooze(Dover)" Then GoTo_Workbook("Bookings").Worksheets("Trip 9").Range ("A1") Else If ComboBox1 = "Pleasurewood Hills(Great Yasrmouth)" Then GoTo_Workbook("Bookings").Worksheets("Trip 10").Range ("A1") Else If ComboBox1 = "Amsterdam School Trip(Amsterdam)" Then GoTo_Workbook("Bookings").Worksheets("Trip 11").Range ("A1") Else If ComboBox1 = "Olympic Village School Trip(London)" Then GoTo_Workbook("Bookings").Worksheets("Trip 12").Range ("A1") Else If ComboBox1 = "Celebrity Dancing On Ice(Nottingham)" Then GoTo_Workbook("Bookings").Worksheets("Trip 13").Range ("A1") Else If ComboBox1 = "X Factor Tour(Cardiff)" Then GoTo_Workbook("Bookings").Worksheets("Trip 14").Range ("A1") Else If ComboBox1 = "Alton Towers Halloween Weekend" Then GoTo_Workbook("Bookings").Worksheets("Trip 15").Range ("A1") End If End If End If End If End If End If End If End If End If End If End If End If End If End If End If End Sub
I nned this for my a level project so if you can get back to me asap i would be grateful.
Cheers
Last edited by Domintor2992; 11-25-2009 at 10:46 AM. Reason: forum rules
Does it work?
Replace the "else" with "Elseif", then you would only require one "End If"
You may need to dim the workbook, at the beggining
Untested.
Code:Dim wb As Workbook Set wb = Workbooks("Bookings") If ComboBox1 = "Old Trafford Tour(Manchester)" Then GoTo_wb.Worksheets("Trip 1").Range ("A1") ElseIf ComboBox1 = "Sister Act(London)" Then GoTo_wb.Worksheets("Trip 2").Range ("A1") ElseIf ComboBox1 = "The Lion King(London)" Then GoTo_wb.Worksheets("Trip 3").Range ("A1") ElseIf ComboBox1 = "Christmas Shopping(London)" Then GoTo_wb.Worksheets("Trip 4").Range ("A1") ElseIf ComboBox1 = "Edinburgh Festival(Edinburgh)" Then GoTo_wb.Worksheets("Trip 5").Range ("A1") ElseIf ComboBox1 = "The Gadget Show Live(Birmingham)" Then GoTo_wb.Worksheets("Trip 6").Range ("A1") ElseIf ComboBox1 = "Disneyland Paris(Paris)" Then GoTo_wb.Worksheets("Trip 7").Range ("A1") ElseIf ComboBox1 = "Port Aventura(Barcelona)" Then GoTo_wb.Worksheets("Trip 8").Range ("A1") ElseIf ComboBox1 = "Booze Crooze(Dover)" Then GoTo_wb.Worksheets("Trip 9").Range ("A1") ElseIf ComboBox1 = "Pleasurewood Hills(Great Yasrmouth)" Then GoTo_wb.Worksheets("Trip 10").Range ("A1") ElseIf ComboBox1 = "Amsterdam School Trip(Amsterdam)" Then GoTo_wb.Worksheets("Trip 11").Range ("A1") ElseIf ComboBox1 = "Olympic Village School Trip(London)" Then GoTo_wb.Worksheets("Trip 12").Range ("A1") ElseIf ComboBox1 = "Celebrity Dancing On Ice(Nottingham)" Then GoTo_wb.Worksheets("Trip 13").Range ("A1") ElseIf ComboBox1 = "X Factor Tour(Cardiff)" Then GoTo_wb.Worksheets("Trip 14").Range ("A1") ElseIf ComboBox1 = "Alton Towers Halloween Weekend" Then GoTo_wb.Worksheets("Trip 15").Range ("A1") End If
thanks for your attempt but when i copied your code into my spreadsheets and ran the user form, the button that this action is supposed to occur on didnt do anything.
I believe you need to the word "Application"
Code:Dim wb As Workbook Set wb = Workbooks("Book2") If ComboBox1 = "May" Then Application.Goto wb.Worksheets("Sheet1").Range("A1") ElseIf ComboBox1 = "June" Then Application.Goto wb.Worksheets("Sheet2").Range("A1") End If
didnt work... still does nothing when i click the button... this is what my code looks like now
Code:
sorry if thats not in the code box thing, i dont know how to put it inCode:Private Sub CommandButton1_Click() Dim wb As Workbook Set wb = Workbooks("Bookings") If ComboBox1 = "Old Trafford Tour(Manchester)" Then Application.Goto wb.Workheets("Trip 1").Range("A1") ElseIf ComboBox1 = "Sister Act(London)" Then Application.Goto wb.Workheets("Trip 2").Range("A1") ElseIf ComboBox1 = "The Lion King(London)" Then Application.Goto wb.Workheets("Trip 3").Range("A1") ElseIf ComboBox1 = "Christmas Shopping(London)" Then Application.Goto wb.Workheets("Trip 4").Range("A1") ElseIf ComboBox1 = "Edinburgh Festival(Edinburgh)" Then Application.Goto wb.Workheets("Trip 5").Range("A1") ElseIf ComboBox1 = "The Gadget Show Live(Birmingham)" Then Application.Goto wb.Workheets("Trip 6").Range("A1") ElseIf ComboBox1 = "Disneyland Paris(Paris)" Then Application.Goto wb.Workheets("Trip 7").Range("A1") ElseIf ComboBox1 = "Port Aventura(Barcelona)" Then Application.Goto wb.Workheets("Trip 8").Range("A1") ElseIf ComboBox1 = "Booze Crooze(Dover)" Then Application.Goto wb.Workheets("Trip 9").Range("A1") ElseIf ComboBox1 = "Pleasurewood Hills(Great Yasrmouth)" Then Application.Goto wb.Workheets("Trip 10").Range("A1") ElseIf ComboBox1 = "Amsterdam School Trip(Amsterdam)" Then Application.Goto wb.Workheets("Trip 11").Range("A1") ElseIf ComboBox1 = "Olympic Village School Trip(London)" Then Application.Goto wb.Workheets("Trip 12").Range("A1") ElseIf ComboBox1 = "Celebrity Dancing On Ice(Nottingham)" Then Application.Goto wb.Workheets("Trip 13").Range("A1") ElseIf ComboBox1 = "X Factor Tour(Cardiff)" Then Application.Goto wb.Workheets("Trip 14").Range("A1") ElseIf ComboBox1 = "Alton Towers Halloween Weekend" Then Application.Goto wb.Workheets("Trip 15").Range("A1") End If End Sub![]()
Last edited by davesexcel; 11-24-2009 at 08:16 AM. Reason: You cannot use quick reply if you are submitting code, because the code icon "#" is not in quick reply
hey ive just read the rules for the forum, didnt realise it would be so strict but never mind its helpful so i will follow them...
and according to excel the 2 workbooks are already linked.
Bookings.xls
Invoice Workbook.xls
there we go
This is in the combo box Old Trafford Guided Tour (Manchester) They don't match,Code:If ComboBox1 = "Old Trafford Tour(Manchester)" Then Application.Goto wb.Workheets("Trip 1").Range("A1")
Most of what is in the code and the ComboBox do not match.
Another issue could be that Worksheets is spelled wrong in every line
Solved.. thank you for your help... the last thing you suggested made it work.
all working perfect now
Cheers
Dom
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks