I still wish we could edit our posts on this forum. I must average about 3 corrections to every post I make.
I reread your question and see that I gave the wrong answer twice. If you truly want to implement a shopping cart in Excel, I imagine you would want to allow for more than 1 of each item. I include two examples, one which allows for a quantity column and one which doesn't.
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
Dim pcelCell As Range
Dim pdblSum As Double
Dim plngMaxRow As Long
Dim plngMaxCol As Long
plngMaxRow = Sh.UsedRange.Row + Sh.UsedRange.Rows.Count
plngMaxCol = Sh.UsedRange.Column + Sh.UsedRange.Columns.Count
For Each pcelCell In Target.Cells
If pcelCell.Row > plngMaxRow Or pcelCell.Column > plngMaxCol Then Exit For
If Not IsNumeric(pcelCell) Then
' Cells(pcelCell.Row, pcelCell.Column + 1) points to the quantity cell,
' in this case, it is the same row, next column. We set this to
' 1, because 0 is meaningless (the user won't select the item for 0).
If Cells(pcelCell.Row, pcelCell.Column + 1) = 0 Then Cells(pcelCell.Row, pcelCell.Column + 1) = 1
pdblSum = pdblSum + Cells(pcelCell.Row, pcelCell.Column + 1) * Prices(pcelCell.Value)
End If
Next
Application.StatusBar = "Sum=" & pdblSum
End Sub
And the example with no quantity input:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
Dim pcelCell As Range
Dim pdblSum As Double
Dim plngMaxRow As Long
Dim plngMaxCol As Long
plngMaxRow = Sh.UsedRange.Row + Sh.UsedRange.Rows.Count
plngMaxCol = Sh.UsedRange.Column + Sh.UsedRange.Columns.Count
For Each pcelCell In Target.Cells
If pcelCell.Row > plngMaxRow Or pcelCell.Column > plngMaxCol Then Exit For
If Not IsNumeric(pcelCell) Then
pdblSum = pdblSum + Cells(pcelCell.Row, pcelCell.Column + 1) * Prices(pcelCell.Value)
End If
Next
Application.StatusBar = "Sum=" & pdblSum
End Sub
And both of these require a second function to define the prices of your items.
Private Function Prices(Item As String)
Prices = 0
If Item = "Car" Then Prices = 25000
If Item = "Rock" Then Prices = 2.5
If Item = "Pencil" Then Prices = 0.99
If Item = "Penny" Then Prices = 0.01
End Function
And cells bearing the text "Car" will add 25000 times the quantity, if specified, and so on.