PDA

View Full Version : [SOLVED:] 'Run time error 1004 method 'range' of object'_worksheet' failed



GEORGE PERRY
04-01-2023, 05:29 AM
Private Sub Worksheet_Change(ByVal Target As Range)
'On change of item, if Row found and add to receipt
If Not Intersect(Target, Range("E10")) Is Nothing And Range("E10").Value <> Empty Then AddItem
'On Change Of Price Or Qty For Added Item
If Not Intersect(Target, Range("F8,F6")) Is Nothing And Range("B4").Value = False And Range("B6").Value = Empty Then
Dim ReceiptRow As Long
ReceiptRow = Range("B6").Value 'Receipt Row
If Not Intersect(Target, Range("F6")) Is Nothing Then Range("M" & ReceiptRow).Value = Target.Value 'Update Price
If Not Intersect(Target, Range("F8")) Is Nothing Then Range("L" & ReceiptRow).Value = Target.Value 'Update Qty
End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'On Selection Of Receipt Item, load item details
If Not Intersect(Target, Range("K10:N9999")) Is Nothing And Range("K" & Target.Row).Value <> Empty Then
Range("B6").Value = Target.Row 'Selection Row
Range("B4").Value = True
Range("E3").Value = Range("K" & Target.Row).Value 'Item Name
Range("F8").Value = Range("L" & Target.Row).Value 'Item Qty
Range("F6").Value = Range("M" & Target.Row).Value 'Item Price
Range("B4").Value = False
End If
End Sub

p45cal
04-01-2023, 06:31 AM
One of the conditions for reaching this line:
If Not Intersect(Target, Range("F6")) Is Nothing Then Range("M" & ReceiptRow).Value = Target.Value 'Update Price
is that B6 should be empty:
…and Range("B6").Value = Empty Then
but the first thing that happens is that ReceiptRow is assigned a value from B6, which is empty, so ReceiptRow gets assigned 0:
ReceiptRow = Range("B6").Value 'Receipt Row
that means that the second part of this line:
If Not Intersect(Target, Range("F6")) Is Nothing Then Range("M" & ReceiptRow).Value = Target.Value 'Update Price
translates to:
If Not Intersect(Target, Range("F6")) Is Nothing Then Range("M" & 0).Value = Target.Value 'Update Price
which errors because there is no cell M0 (no row 0).

I can't advise on what code changes are needed because I don't know what you're tryinmg to do.

GEORGE PERRY
04-03-2023, 05:09 PM
thank you very much sir, am a learner so any piece of project i see i try to practice.
am trying to create a POINT OF SALE with Excel but it seems my project is having problems when i run the application after writing the codes. So i will send you the application so that you review to see where am wrong in the codes because i cant get it.

Aussiebear
04-03-2023, 05:27 PM
@ George Perry, Please note that if you are asking for assistance to develop the software in total, you are pushing the boundaries some what. The major purpose of the forum is for the asking of single issue queries, rather than full scale development. Some one here may be interested in taking on such a project, but be advised its highly likely that it would need to be on a pay for service type basis.

arnelgp
04-03-2023, 07:36 PM
and instead of Building something from Excel, there are lots of GNU POS on the net.

Paul_Hossler
04-03-2023, 07:41 PM
thank you very much sir, am a learner so any piece of project i see i try to practice.
am trying to create a POINT OF SALE with Excel but it seems my project is having problems when i run the application after writing the codes. So i will send you the application so that you review to see where am wrong in the codes because i cant get it.

I reformatted the macros using indents and blank lines to make it easier to read (for me at least)

It looks nice and I can see the 2 backup sheets, but on the POS sheet there didn't seem to be any actions

You might have the Items button call a macro that has a UserForm and probably a ListBox control show the 'database' of Items and a TextBox to enter quantity, etc.

Another approach might be to use a Double Click on Items. I added a simple example to my re-format



Option Explicit


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim r As Range, rData As Range

Set rData = Me.Cells(1, 1).CurrentRegion

Set r = Target.Cells(1, 1)

If Intersect(r, rData) Is Nothing Then Exit Sub

With r.EntireRow

'actually put these where they go in your POS
MsgBox "Item ID = " & .Cells(1, 1).Value & vbCrLf & _
"Item Name = " & .Cells(1, 2).Value & vbCrLf & _
"Item Description = " & .Cells(1, 3).Value & vbCrLf & _
"Price = " & .Cells(1, 4).Value
End With
End Sub



AussieBear is correct that building a full blown POS is a lot to ask. If you have questions you can always come back and we'll be glad to help

GEORGE PERRY
04-04-2023, 02:14 AM
Thanks to you all for the support.