Consulting

Results 1 to 7 of 7

Thread: 'Run time error 1004 method 'range' of object'_worksheet' failed

  1. #1

    'Run time error 1004 method 'range' of object'_worksheet' failed

    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
    Attached Images Attached Images
    Last edited by Aussiebear; 04-01-2023 at 11:41 AM. Reason: Added code tags to supplied code

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,877
    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.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    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.
    Attached Files Attached Files

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,089
    Location
    @ 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.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    and instead of Building something from Excel, there are lots of GNU POS on the net.

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,738
    Location
    Quote Originally Posted by GEORGE PERRY View Post
    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
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  7. #7
    Thanks to you all for the support.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •