chrislowe2006
New Member
- Joined
- Feb 13, 2014
- Messages
- 8
Hi, First of all thanks in advanced for your help. I'm fairly new to coding VBA in Excel. so I have managed to create the following code (which works as intended) and I am curious to know if there is anyway to simplify it as I need to add more lines to it.
The intended result is that when a person clicks a button the seat is booked and reflected on another sheet.
As you can see it is a long peice of code...
The intended result is that when a person clicks a button the seat is booked and reflected on another sheet.
Code:
Sub BookSeat()
Dim D1 As String
Dim D2 As String
Dim D3 As String
Dim Seat As String
D1 = Sheets("Booking").Range("E8").Value
D2 = Sheets("Booking").Range("F8").Value
D3 = Sheets("Booking").Range("J8").Value
Seat = Sheets("Booking").Range("I8").Value
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "1A" And D3 = "Available" Then
Sheets("JB114").Range("S1A").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "1B" And D3 = "Available" Then
Sheets("JB114").Range("S1B").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "1D" And D3 = "Available" Then
Sheets("JB114").Range("S1D").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "1F" And D3 = "Available" Then
Sheets("JB114").Range("S1F").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "2A" And D3 = "Available" Then
Sheets("JB114").Range("S2A").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "2B" And D3 = "Available" Then
Sheets("JB114").Range("S2B").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "2D" And D3 = "Available" Then
Sheets("JB114").Range("S2D").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "2F" And D3 = "Available" Then
Sheets("JB114").Range("S2F").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "3A" And D3 = "Available" Then
Sheets("JB114").Range("S3A").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "3B" And D3 = "Available" Then
Sheets("JB114").Range("S3B").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "3D" And D3 = "Available" Then
Sheets("JB114").Range("S3D").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "3F" And D3 = "Available" Then
Sheets("JB114").Range("S3F").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "4A" And D3 = "Available" Then
Sheets("JB114").Range("S4A").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "4B" And D3 = "Available" Then
Sheets("JB114").Range("S4B").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "4D" And D3 = "Available" Then
Sheets("JB114").Range("S4D").Value = "Occupied"
End If
If D1 = "Manchester" And D2 = "Amsterdam" And Seat = "4F" And D3 = "Available" Then
Sheets("JB114").Range("S4F").Value = "Occupied"
End If
As you can see it is a long peice of code...