+ Reply to Thread
Results 1 to 2 of 2

VBA to find subtotal on Excel file opened on Teams sharepoint

  1. #1
    Registered User
    Join Date
    03-15-2022
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    1

    Exclamation VBA to find subtotal on Excel file opened on Teams sharepoint

    Hi Team,

    I have a code which opens a file on Teams sharepoint and finds a part number in a column and then finds the subtotal of the inventory of that part and sends a message mentioning the amount of stock available for this item. But, when the file is opened on Teams, the code is not working entirely and the code stops running with an error in the below highlighted step. The error shown is "Type mismatch". Please help.

    Sub pdc()

    Dim i As Integer
    Dim f As Workbook
    Dim pno As String, Summary As String
    Dim lastrow As Long
    Dim Sum As Integer
    Dim Rng As Range
    Dim wb As Workbook
    Dim xl As Object

    Set wb = ActiveWorkbook
    If wb.Worksheets(1).Range("G3").Value = 2 Then
    MsgBox "This function is not applicable for complete valves."
    End
    End If

    lastrow = wb.Worksheets("Emerson COMMERCIAL OFFER").Range("D:D").Find(What:="*", _
    LookAt:=xlPart, _
    LookIn:=xlFormulas, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious, _
    MatchCase:=False).Row

    sFileName = "xxx"
    Set xl = CreateObject("Excel.Application")
    Set f = xl.Application.Workbooks.Open(Filename:=sFileName, ReadOnly:=True)
    For i = 24 To lastrow
    pno = wb.Worksheets("Emerson COMMERCIAL OFFER").Cells(i, 4).Value
    f.Worksheets(1).Range("A1:L408").AutoFilter Field:=4, Criteria1:="=*" & pno & "*"
    If f.Worksheets(1).AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1 > 0 Then
    With f.Worksheets(1)
    Set Rng = .Range(.Cells(2, 10), .Cells(.Rows.Count, 10).End(xlUp))
    End With
    Sum = Application.WorksheetFunction.Subtotal(109, Rng)
    Summary = Summary & pno & " - " & Sum & " pcs" & vbLf
    Else
    Summary = Summary & pno & " - " & "No stock in PDC" & vbLf
    End If
    Next i
    wb.Worksheets("Emerson COMMERCIAL OFFER").Activate
    f.Worksheets(1).ShowAllData
    f.Close False
    Set f = Nothing
    MsgBox Summary


    End Sub

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,220

    Re: VBA to find subtotal on Excel file opened on Teams sharepoint

    Please edit your first post and put the code in the tags (highlight the code content and press the [#] button). Tagging your code is mandatory for this forum.

    In this code, you are navigating in two instances of Excel (possibly completely unnecessary). It looks like you are trying to pass a parameter from one instance to the other. Try to pass in the same instance:
    Please Login or Register  to view this content.
    Artik

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Date & time picker not supported by ms teams & sharepoint
    By YSFG in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-09-2021, 11:10 AM
  2. [SOLVED] VBA: Show pop-up when Excel file is opened in browser (e.g. SharePoint / OneDrive)
    By kingofcamden in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-01-2021, 08:43 AM
  3. Excel Formula showing #VALUE as soon as it gets opened in SharePoint
    By rubz71 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-30-2021, 12:43 AM
  4. Replies: 0
    Last Post: 03-23-2021, 05:04 PM
  5. VBA to select SharePoint Content Type when saving Excel file to SharePoint
    By Luffk73 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-24-2017, 05:22 PM
  6. Replies: 0
    Last Post: 10-08-2013, 10:54 AM
  7. How to set a Global Macros so that it gets opened every time an excel file is opened?
    By pericopericone in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2013, 05:53 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1