Visual Studio Developer Center > Visual Studio Forums > Visual Studio Tools for Office > Checking Row number from a Range in sheet Change Event
Ask a questionAsk a question
 

AnswerChecking Row number from a Range in sheet Change Event

  • Friday, November 06, 2009 1:34 AMSankara_narayanan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I am working on VSTO excel project, and i have to handle the following situation.

    say user pastes some value into cell 1 of row 1, row 3 and row 5, which are not continuous row,

    i am currently validating the entered data in sheet_change event.

    is there a way that i can find out the rownumber of the affected rows using the Target object available within sheet_change event?

    target.row, gives beginning row number, target.row.count gives number of rows affected, but is there a way i can know that out of the 3 rows that got affected, they are row 1, row 3 and row 5 of the sheet????

    any help in this regard is highly appreciated.

Answers

  • Monday, November 09, 2009 9:21 AMBessie ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello Sankara,

    In the change event handler, Here is the Target range as a passed argument. We could use get_Address method to get the cells included in this range [See: get_Address Method]. Code like this,

                string address =Target.get_Address(true, true, Excel.XlReferenceStyle.xlA1, true, true);
                MessageBox.Show(address);

    For test, in my side, it shows a message box.

    If I have mistaken this scenario, please point me out.

    Best regards,
    Bessie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Monday, November 09, 2009 2:10 PMincre-d Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Without using a databinding of somesort, there will be now way to identify the actual rows that changed.

    You could track all the data in the sheet, which would be a kind of databinding, and you can use VSTO to keep a track of all cells that get changed, but then you will only know what changed, since the last change, you won't pick up the first change.

    Let me know if the latter scenarios might interest you.

All Replies

  • Monday, November 09, 2009 9:21 AMBessie ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello Sankara,

    In the change event handler, Here is the Target range as a passed argument. We could use get_Address method to get the cells included in this range [See: get_Address Method]. Code like this,

                string address =Target.get_Address(true, true, Excel.XlReferenceStyle.xlA1, true, true);
                MessageBox.Show(address);

    For test, in my side, it shows a message box.

    If I have mistaken this scenario, please point me out.

    Best regards,
    Bessie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Monday, November 09, 2009 2:10 PMincre-d Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Without using a databinding of somesort, there will be now way to identify the actual rows that changed.

    You could track all the data in the sheet, which would be a kind of databinding, and you can use VSTO to keep a track of all cells that get changed, but then you will only know what changed, since the last change, you won't pick up the first change.

    Let me know if the latter scenarios might interest you.