Results 1 to 2 of 2

Thread: VBscript if condition with count.row

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2017
    Posts
    3

    VBscript if condition with count.row

    Hello everybody,
    I would like to create a VBS with the following condition.
    I have to count the filtered rows in sheet ZMMLTA and
    If count.rows is less than 1, skip
    If count.rows is more than 2, do the transaction below.
    The code I write doesn't work. Please help me!


    filePath = "C:\Data\SapScript\ZMMLTA\ZMMLTA.xlsm"
    Set EXC = CreateObject("Excel.Application")
    EXC.Workbooks.Open(filepath)

    Dim Lst_row
    For i = 2 to objsheet.UsedRange.Rows.Count
    Lst_row = ZMMLTA.cells(i, 1).End(xlup).row

    If [Lst_row > 1] then

    session.findById("wnd[0]").maximize
    session.findById("wnd[0]/tbar[0]/okcd").text = "/nzmmlta"
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[0]/usr/btn%_SO_MATNR_%_APP_%-VALU_PUSH").press
    session.findById("wnd[0]/usr/btn%_SO_MATNR_%_APP_%-VALU_PUSH").press
    session.findById("wnd[0]/usr/ctxtSO_WERKS-LOW").text = Plant
    session.findById("wnd[0]/usr/ctxtSO_MATNR-LOW").setFocus
    session.findById("wnd[0]/usr/ctxtSO_MATNR-LOW").caretPosition = 0
    session.findById("wnd[0]/usr/btn%_SO_MATNR_%_APP_%-VALU_PUSH").press
    session.findById("wnd[1]/tbar[0]/btn[16]").press
    session.findById("wnd[1]/tbar[0]/btn[24]").press
    session.findById("wnd[1]/tbar[0]/btn[8]").press
    session.findById("wnd[0]/usr/ctxtSO_AUTET-LOW").text = ""
    session.findById("wnd[0]/usr/ctxtSO_AUTET-HIGH").text = ""
    session.findById("wnd[0]/usr/ctxtSO_KDATE-LOW").setFocus
    session.findById("wnd[0]/usr/ctxtSO_KDATE-LOW").caretPosition = 0
    session.findById("wnd[0]").sendVKey 2
    session.findById("wnd[1]/usr/cntlOPTION_CONTAINER/shellcont/shell").setCurrentCell 1,"TEXT"
    session.findById("wnd[1]/usr/cntlOPTION_CONTAINER/shellcont/shell").selectedRows = "1"
    session.findById("wnd[1]/usr/cntlOPTION_CONTAINER/shellcont/shell").doubleClickCurrentCell
    session.findById("wnd[0]/usr/ctxtSO_KDATE-LOW").text = Date
    session.findById("wnd[0]/usr/ctxtSO_KDATE-LOW").caretPosition = 10
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[0]/tbar[1]/btn[8]").press
    session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").setCurrentCell -1,""
    session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectAll
    session.findById("wnd[0]/tbar[1]/btn[2]").press

    ELSE
    session.findById("wnd[0]").maximize
    session.findById("wnd[0]/tbar[0]/okcd").text = "/nzmmlta"
    END IF

    EXC.Run "Z"
    EXC.Visible = True

    I got error message: Expected Next

  2. #2

    Thread Starter
    New Member
    Join Date
    May 2017
    Posts
    3

    Re: VBscript if condition with count.row

    Please help me in solving this issue.
    To count the rows a used:

    RigheFiltrate = ActiveSheet.ListObjects("ZMMLTA").Range.SpecialCells(xlCellTypeVisible).Rows.Count

    But an error message appear:
    Object required: 'ActiveSheet'
    How to solve this problem?

Posting Permissions

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



Click Here to Expand Forum to Full Width