+ Reply to Thread
Results 1 to 6 of 6

Row() function use in EXCEL VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    20

    Row() function use in EXCEL VBA

    I have User Defined Function - getRefi(Row()).
    I want to assign this function as value to some sepecific cells in worksheet.
    I wrote a function as given below, but excel is not recognises the Row() funciton, while it works fine in workbook.

    Public Function displayExpectedValues()
    startRowValue = InputBox("Enter FirstRow Number to read data")
    EndRowValue = InputBox("Enter Last Row Number to read Data")
    
    For Each c In Sheets("Reasult Reader").Range("Q" & startRowValue &":Q" & EndRowValue )
        c.Offset(0, 1) = getIZV(Application.WorksheetFunction.Row())  ' excel is not recognizing row() function
        c.Offset(0, 2) = getIZV(Row()) ' excel is not recognizing row() function
        startRowValue = startRowValue  + 1
        if startRowValue  = EndRowValue Then
              Exit for
        End If
    Next c
    End Function
    Last edited by syparth; 04-15-2013 at 11:44 AM.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Row() function use in EXCEL VBA

    please add code tags to your post
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,379

    Re: Row() function use in EXCEL VBA

    According to http://msdn.microsoft.com/en-us/libr.../ff836235.aspx the Row() worksheet function is NOT on the list of worksheet functions available to VBA. It seems likely that you will need a different approach to get the row number.

    If this is really a function procedure that you intend to call from a spreadsheet cell, I would get rid of the input boxes and pass that information to the function through the argument list. I would probably also structure the other input and output differently.

    If this is not intended to be called from a spreadsheet cell, I would probably change it to a sub procedure.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Row() function use in EXCEL VBA

    c.row will give you the number you want

  5. #5
    Registered User
    Join Date
    03-27-2013
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Row() function use in EXCEL VBA

    I have made a bit little changes to the function and have used "c.row" but it is thowing some different error now.

    Public Function displayExpectedValues()
    startRowValue = InputBox("Enter FirstRow Number to read data")
    EndRowValue = InputBox("Enter Last Row Number to read Data")
    
    c = Sheets("Result Reader").Range("Q" & CStr(startRowValue))
    
    Do While startRowValue < EndRowValue
        c.Offset(0, 1) = getIZV(c.Row) ' Object Required error
        c.Offset(0, 3) = getIZV(c.Row)
        c.Offset(0, 2) = c.Offset(0, 1).Value + c.Offset(0, 3).Value
        startRowValue = startRowValue + 1
    Loop
    End Function

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,379

    Re: Row() function use in EXCEL VBA

    You haven't specifically dimensioned c as anything, so it defaults to a variant, which can hold just about any data type. So when you let c=sheet("result reader")..., it probably assumes you mean that c should equal the value of whatever is in that cell. To see this, step through your code, with a watch set for c. I expect under "type" it will say something like "variant/double" or "variant/string" depending on what is in that cell.

    What you want is to set c as an object reference to the specified range/cell object. In order to do this, you must use the Set statement.
    Set c=sheets("result reader").range("Q1")
    . You might search VBA help for the set statement for further details. Using the set statement, I would expect you to see "variant/range" for the c's data type.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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