Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

suddenly show error for code was work without problem

0

Hi,

I'm confused why the code shows error object doesn't support this property  or method in this line 

txt = ap.TextJoin("", False, rng)
for this part of code 
Private Sub DoIt(rng As Range, r As Range)
    Dim txt, x, ap As Object, c As Range
    Set ap = Application
    txt = ap.TextJoin("", False, rng)
    With Sheets("inv").Cells(1).CurrentRegion
        x = .Rows.Count
        x = .Parent.Evaluate("iferror(match(""" & txt & """," & _
            "a1:a" & x & "&b1:b" & x & "&c1:c" & x & ",0),0)")
        If x > 0 Then
            Set c = .Parent.Cells(x, 5): x = c.Value
        End If
    End With
       MsgBox ap.TextJoin(" ", False, rng) & vbLf & IIf(x - r < 0, _
       "You can't subtract", "Remains : " & x - r), , "Current stock : " & x
    If x - r < 0 Then
        Application.EnableEvents = False
        r.ClearContents
        Application.EnableEvents = True
    Else
        c = c - r
    End If
End Sub

when I enter qty in column E for ENTER sheet will match B: D columns with A:C columns in INV sheet then will subtract QTY  in column E in INV sheet from column E in ENTER sheet  and show message what's the vailable qty and remaining qty for ID  after subtraction.

the code was work well , why now doesn't work?!!

Answer
Discuss

Answers

0
Selected Answer

Kalil

Revision #1, 26 Sepetember 2024

The same file works in Excel 365 but not Excel 2016- since the TEXTJOIN function isn't available in 2016 (just 2019, 2021 and 365). I tried it in 2010 and got the error.

In the attached revised file, I've replaced the first TEXTJOIN line with a simple loop through your range rng to produce the same effect (see changes in bold):

Private Sub DoIt(rng As Range, r As Range)
    Dim txt, x, c As Range 'ap As Object,
    Dim Cll As Range

    Set ap = Application
    'txt = ap.TextJoin("", False, rng)
    'Replace with loop through cells in range rng:
    For Each Cll In rng
        txt = txt & Cll.Value
    Next Cll

    With Sheets("inv").Cells(1).CurrentRegion
        x = .Rows.Count
        x = .Parent.Evaluate("iferror(match(""" & txt & """," & _
            "a1:a" & x & "&b1:b" & x & "&c1:c" & x & ",0),0)")
        If x > 0 Then
            Set c = .Parent.Cells(x, 5): x = c.Value
        End If
    End With
       'MsgBox ap.TextJoin(" ", False, rng) & vbLf & IIf(x - r < 0, _
       "You can't subtract", "Remains : " & x - r), , "Current stock : " & x
       MsgBox txt & vbLf & IIf(x - r < 0, _
       "You can't subtract", "Remains : " & x - r), , "Current stock : " & x
    If x - r < 0 Then
        Application.EnableEvents = False
        r.ClearContents
        Application.EnableEvents = True
    Else
        c = c - r
    End If
End Sub

Hope this is what you wanted- if so, please remeber to mark this Answer as Selected.

Discuss

Discussion

Try the same file in 365 if you can- it still works...
I haven't 365  to test it.
Your Forum profile shows Excel 2016- are you using that?
yes
I ask since the TEXTJOIN function isn't available in 2016 (just 2019, 2021 and 365). I tried it in 2010 and got the error. 
bad news!
if you have free time to find alternetive function with office 2010 I truley appreciate. if you can't then forgot it .
thank you for your time.
Kalil (rep: 40) Sep 25, '24 at 2:41 pm
Kalil

If I get chance tomorrow or Friday, I'll try to suggest some code to replace TEXTJOIN for legacy versions of Excel. Should be pretty easy for me but time is the issue.
John_Ru (rep: 6417) Sep 25, '24 at 6:10 pm
Kalil- please see Revision #1, 26 Sepetember 2024 to my Answer (and the file)
John_Ru (rep: 6417) Sep 26, '24 at 6:03 pm
Awesome !
many thanks John.
Kalil (rep: 40) Sep 26, '24 at 6:21 pm
Glad that worked. Thanks for selecting my Answer, Kalil 
John_Ru (rep: 6417) Sep 26, '24 at 6:22 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login