VB programming in Excel, always subscript crosses the line

Updated on technology 2024-05-01
4 answers
  1. Anonymous users2024-02-08

    It's very simple, you don't need to use VBA, you can just use the formula. Here's how:

    A1: 399900

    A2 input: =substitute(substitute(A1+1,4,5),7,8).

    A3 Copy A2 and drag it down.

  2. Anonymous users2024-02-07

    Change it for you, try it or not!

    sub autosr()

    dim str1 as string, str2 as string

    dim a1 as double, a2 as long, i as long

    str1 = "399900": a1 = 399900

    worksheets("sheet1").cells(2, 5).value = 399900

    for i = 3 to 210

    worksheets("sheet1").cells(i, 3).value = worksheets("sheet1").

    cells(i - 1, 3) +1 'Generate the initial value for the next **.

    str1 = str(worksheets("sheet1").cells(i, 3).value) 'Convert the value to a string.

    str2 = replace(str1, "4", "5", 1) 'Replace the 4 in the string with 5.

    str2 = replace(str1, "7", "8", 1) 'Replace 7 with 8 in the string.

    a2 = clng(str2)

    worksheets("sheet1").cells(i, 3).value = a2

    next i

    end sub

  3. Anonymous users2024-02-06

    In Excel, VBA indicates that the subscript is out of bounds, indicating that the object does not exist or the array element does not exist.

    As a simple example: there is no one in the worksheet"January"This worksheet, however, uses sheets("January");The array defines arr(1 to 10), but arr(11) will be used, and the subscript will be out of bounds.

    To put it simply: an out-of-bounds subscript is a quote that is out of scope.

    1. When we enter the following ** in the VBA of Excel and run, there will be a prompt of "Error 9 subscript out of bounds during run". ** Below:

    sub a()

    dim arr() as string

    arr(1) = Hello"

    end sub

    2. In fact, the above "runtime error 9 subscript is out of bounds" is because the defined dynamic array does not determine the dimension and size. This problem can be solved by defining the fixed number of dimensions and dimensions, or by defining the dimensions and dimensions with redim.

    The corrected ** is as follows:

    sub a()

    dim arr() defines a dynamic array.

    dim i as integer

    redim arr(1 to 3) 'Define an array of 3 elements and initialize the array.

    arr(1) =3

    arr(2) =4

    arr(3) =5'In the following statement, redefine an array of 10 elements, clear the previous elements, and reassign new stored variables.

    redim arr(1 to 10)

    for i = 1 to 10

    arr(i) =i

    next i

    end sub, that's it.

  4. Anonymous users2024-02-05

    If you declare an array arr(5), then only the cryptofiber has arr(0) to arr(4) and the 5 elements can be accessed normally, if you use the missing carrier arr(5) to access the 6th element, you will get an out-of-bounds subscript error.

Related questions
2 answers2024-05-01

Hehe, it's too simple, and there are many ways. Here's the simplest example: >>>More

12 answers2024-05-01

Not sure what it does?

What are the specific requirements. >>>More

13 answers2024-05-01

Picturebox also works well

Generally, the graphics of each chess piece are collected in a single diagram. >>>More

3 answers2024-05-01

private sub timer1_timer()= "Current Time:" + cstr(time)if = cstr(time) thenmsgbox "The countdown ends" >>>More

10 answers2024-05-01

Set the focus. For example, if you make the text box text1 focus in the program, you can enter the text directly in the text box without clicking the text box with the mouse to make it focus before entering the content. >>>More