Run-time error '1004' Method 'Range' of object '_Global' failed

Rufus Clupea

Board Regular
Joined
Feb 11, 2019
Messages
85
Can't quite see/figure out what I've done wrong (I don't know what I don't know :confused: ).

I'm getting:

Run-time error '1004'

Method 'Range' of object '_Global' failed

I've tracked the error down (I think) to the FOR-NEXT loops in the following snippet of code (edited for brevity/relevance):

Code:
Option Explicit 'ALL VARIABLES MUST BE DECLARED
Option Base 1   'DEFAULT LOWER LIMIT OF ARRAYS = 1

'------------------------------------
'    GLOBAL DECLARATIONS
'------------------------------------    

Dim Array1(1 To 13, 1 To 2) As String
Dim Array2(1 To 13, 1 To 2) As String

'------------------------------------    
Private Sub Update_Arrays()

    Dim i As Integer    'FOR-NEXT Index
    
    Dim a As Integer    'Array1 Index
    Dim d As Integer    'Array2 Index
    
    Dim row As Integer
    
    a = 1               'Array1 Index
    d = 1               'Array2 Index
        
'------------------------------------------------
'    CODE (Deleted) changes the values of a and d
'    to Integers between 1 and 9.  
'------------------------------------------------

    For i = 1 To a
        row = 39 + i:
        Range(Cells(row, 1)).Text = Array1(i, 1):
        Range(Cells(row, 2)).Text = Array1(i, 2)
    Next i

    For i = 1 To d
        row = 39 + i:
        Range(Cells(row, 11)).Text = Array2(i, 1):
        Range(Cells(row, 12)).Text = Array2(i, 2)
    Next i

End Sub

If I "comment" the FOR-NEXT loops, everything runs fine, so I'm assuming (as perilous as that can be :rolleyes: ) that the FOR-NEXT loops are--somehow--the problem. When Un-commented is when I get the error.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Simply remove the word Range & it's associated brackets.
 
Upvote 0
Thank you.

Tried that. Now the error msg. is:

Run-time error '1004'

Unable to set the Text property of the Range class

Hmmm... The source I got the original example from was Excel VBA Programming for Dummies Pg. 118, except that I changed .Value to .Text as the arrays contain text strings, and 'Text' was one of the properties proffered in the drop-down (Silly me).

I just tried changing .Text back to .Value, and that seems to work, along with your suggestion (though I don't understand why, or why using the example with 'Range' is wrong. :confused: )

I think I miss the '70s... :rolleyes:
 
Upvote 0
.Text is a read only property, which is why it didn't work.
As for the Range you can use something like
Code:
Range(Cells(1,2),Cells(10,2))
but it doesn't work if you only have a single cell in the range, although I don't know why.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top