0

I'm trying to fill 1299 cells in a row with the value 0530 using the following code:

Sub FillValues()

    Dim X As Integer

    For X = 2 To 1300

        Worksheets("Table1").Range("B" & X).Value = "'0530"

    Next X

End Sub

For some reason it doesn't work and I don't know why. The error is "Index beyond the valid range."

D3merzel
  • 63
  • 10
  • 1
    You need to either format the range as a string (e.g., with the `:` included), or you need to define it using `Cells`. You've got a strange mix of both going on. Also, you might have an extra apostrophe in your value. – SmrtGrunt Jun 29 '19 at 13:46
  • 1
    Possible duplicate of [Excel VBA set multiple cells to the same value](https://stackoverflow.com/questions/30638716/excel-vba-set-multiple-cells-to-the-same-value) – Mikku Jun 29 '19 at 14:02

1 Answers1

2

Please try (no loop):

Worksheets("Table1").Range("B2:B1300").Value = "'0530"
pnuts
  • 58,317
  • 11
  • 87
  • 139