A Way to List Multiple Services Before Code Runs

L

Legacy 436357

Guest
Hello,

I have this code that will update the appropriate vehicle when the selected service is entered.

How it works now is one service is entered at a time. On most occasions it would be better to be able to select multiple services.

Does anyone have ideas on how to perhaps have the list of services and select the Date, O/D, Vehicle, and type of service?

Thank you I appreciate any help or advice.

Excel Workbook
ABCD
2Date of ServiceVehicleOdometerWork Performed and Service Schedule
307/29/20172014 Dodge Dart50100Changed engine oil and filter
407/29/20172014 Dodge Dart50100Checked battery terminals and cables for corrosion
507/29/20172014 Dodge Dart50100Checked brake fluid
Service Entries
#VALUE!





Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim SheetName As String         ' Vehicle name
Dim sh As Worksheet             ' Vehicle worksheet
Dim DateofService As Date       ' Date of service
Dim Odometer As Long            ' Odometer reading
Dim TypeService As String       ' Type of service
Dim rng As Range                ' Range for find command
Dim LCol As Long                ' Last column of found service

If Target.Cells.Count > 1 Then Exit Sub

If Intersect(Target, Range("Table_Service[Work Performed and Service Schedule]")) Is Nothing Then Exit Sub

SheetName = Cells(Target.Row, "B")
DateofService = Cells(Target.Row, "A")
Odometer = Cells(Target.Row, "C")
TypeService = Cells(Target.Row, "D")

Set sh = Sheets(SheetName)

' Look for type of service on sheet
Set rng = sh.Range("A3:A500").Find(TypeService, LookIn:=xlValues, lookat:=xlWhole)
If rng Is Nothing Then
    ' If service isn't found, exit the program
    MsgBox TypeService & " was not found for vehicle, " & SheetName
    Exit Sub
Else
    ' Shift history over by copying everything two columns to left and then moving existing data over
    LCol = sh.Cells(rng.Row, Columns.Count).End(xlToLeft).Column
    
    If LCol = 4 Then GoTo PutCells
    ' if the first entry, just put the cells
    
    If LCol = 6 Then
        ' If the second entyr copy the cells over
        sh.Cells(rng.Row, "G") = sh.Cells(rng.Row, "E")
        sh.Cells(rng.Row, "H") = sh.Cells(rng.Row, "F")
    Else
        ' For later entries move the range and copy the cells
        sh.Range(sh.Cells(rng.Row, "G"), sh.Cells(rng.Row, LCol)).Copy sh.Cells(rng.Row, "I")
        sh.Cells(rng.Row, "G") = sh.Cells(rng.Row, "E")
        sh.Cells(rng.Row, "H") = sh.Cells(rng.Row, "F")
    End If
    
PutCells:
    ' Put new values in the appropriate place
    sh.Cells(rng.Row, "E") = DateofService
    sh.Cells(rng.Row, "F") = Odometer
End If

End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top