Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5974385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:56:09+00:00 2026-05-22T20:56:09+00:00

Trying to replace Cells(RowIndex,ColumnIndex).Value() calls by row-wise references for performance, I permanently fail at

  • 0

Trying to replace Cells(RowIndex,ColumnIndex).Value() calls by row-wise references for performance, I permanently fail at referencing the result.

Starting with Excel Interop – Efficiency and performance, which contains the tip to use get_range, i.e.

//get values
object[,] objectArray = shtName.get_Range("A1:Z100").Value2;
iFace = Convert.ToInt32(objectArray[1,1]);

//set values
object[,] objectArray = new object[3,1] {{"A"}{"B"}{"C"}};
rngName.Value2 = objectArray;

I figured I cannot use get_Range since that method is not callable for me, says VB at run-time (not a visible member).

Now I came up with stuff like:

Dim Values As Object(,)
Values = Sheet.Range(Sheet.Cells(RowIndex, 1), Sheet.Cells(2, 17)).Value2
For Index As Integer = 0 To 16
  MsgBox(Values(0, Index))
Next

However, referencing Values with two dimension indices always returns an “index was outside the bounds of the array” exception. Inspecting the array with the debugger shows a nice 2-dimensional array which should has 17 elements on the second dimension, so Value (0,0) should indeed be a valid reference — but it isn’t:

The debugger lets me inspect Value, I can also drill down to Value(0,0) and see the correct value, but re-evaluating just that element, i.e. inspecting “Value (0,0)” returns above message.

How can I reference what my Value2 call returns?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:56:10+00:00Added an answer on May 22, 2026 at 8:56 pm

    Perhaps something like this? Note that if you want the array to have the column as the first element you’d use change the line below as noted:

    Imports Microsoft.Office.Interop
        Module Module1
            Sub main()
                Dim appExcel As Excel.Application
                Dim wb As Excel.Workbook
                Dim ws As Excel.Worksheet
                Dim values As Object
    
                appExcel = GetObject(, "Excel.Application")
                wb = appExcel.Workbooks(1)
                ws = wb.Worksheets(1)
                With ws
                    values = .Range(.Cells(1, 1), .Cells(2, 5)).Value2
                    'if column is first element use appExcel.Worksheetfunction.Transpose(.Range(.Cells(1, 1), .Cells(2, 5)).Value2)
                    For i As Int32 = LBound(values, 1) To UBound(values, 1)
                        For j As Int32 = LBound(values, 2) To UBound(values, 2)
                            System.Windows.Forms.MessageBox.Show(values(i, j))
                        Next j
                    Next
                End With
            End Sub
        End Module
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to replace function calls written when methods were nonstatic to an
I'm trying to pass a value between forms - in this case, the result
I'm trying to get rid of all DateTime.Now method calls and replace them with
When trying to replace the content of an XML file in C#.NET with a
I'm trying to replace each , in the current file by a new line:
I'm trying to replace the programs that run from my startup directory with a
I'm trying to replace every multiline import inside a Python source file.. So, the
I am trying to replace multiple rows in an Access database to follow a
I am trying to replace a two letter state abbreviation with text then the
I'm trying to replace a call to ::CoCreateGUID so I can generate GUIDs in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.