Results 1 to 4 of 4

Thread: Convert Syntax from VBA to VB.Net

  1. #1

    Thread Starter
    Banned
    Join Date
    Apr 2020
    Location
    https://t.me/pump_upp
    Posts
    61

    Convert Syntax from VBA to VB.Net

    Dear All

    We are moving from VBA to VB.net in our company and I converted many syntaxes from VBA to VB.net except some, this is one of them but I tried as you will see below:

    BBS is the Sheet name in VBA
    ws is the sheet name in VB.net

    The VBA Syntax is :

    Code:
    rgnInp =INDEX(BBS!$D:$D, ROW(BBS!$D$11)+1):INDEX(BBS!$E:$E, MATCH(conBig, BBS!$D:$D))
    conBig = 9.999999999
    I Converted it to VB.Net as below:

    Code:
    rgnInp = xl.WorksheetFunction.Index(ws.Range("D", "D"), ("D11") + 1) : xl.WorksheetFunction.Index(ws.Range("E", "E"),  xl.WorksheetFunction.Match(conBig, ws.Range("D", "D")))
    I can not find what should replace ROW in VB.net

    When the program runs, it gives unhandled Error Exception

    Appreciate your help

    Thanks, Regards

    Moheb Labib

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: Convert Syntax from VBA to VB.Net

    That's Excel, not VBA
    You should ask in the Office Development forum. I'll ask a moderator to move this question...

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,762

    Re: Convert Syntax from VBA to VB.Net

    According to the VBA documents, ROW returns the first row number of the selected reference.

    In this case, your selected range is D11. But if you're hard-coding that cell and adding 1 to it, why not just specify 12:
    Code:
    ... xl.WorksheetFunction.Index(ws.Range("D", "D"), 12) ...
    In fact, it looks like you just want the value from D12. Why not remove the function and just get the value:
    Code:
    Dim rgnInp = xl.Range("D12").Value
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,047

    Re: Convert Syntax from VBA to VB.Net

    It's not plain Excel, and the goal is .NET, so it seems like a pretty clear cross-over question that could work just as well in either location.
    My usual boring signature: Nothing

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