subscript out of range error that doesn't make sense

Foo_Man_Chu

Board Regular
Joined
Jul 22, 2010
Messages
79
I have a spreadsheet where the following code runs after a button is clicked. The code is supposed to ultimately update another spreadsheet from the current spreadsheet. When it runs it gives me a subscript out of range error on this line :

Code:
Workbooks(file).Worksheets("Esc-Gum-LD").Range(F29) = "c"

I've looked around and from what I've seen this is either due to trying to reference an element outside the bounds of an array or trying to refer to something that isn't in the spreadsheet. There is no array involved and the only two values are "Esc-Gum-LD" and the variable "file". I checked and the workbook "file" represents exists and is open and it contains a sheet named "Esc-Gum-LD". Please, can someone help me?

Here is my code:



Code:
Private Sub updateTargetSpreadsheet(Optional ByVal strAddr As String, Optional ByVal strColRow As String, Optional ByVal strColor As String, Optional ByVal strType As String)
    Dim file As String
    Dim strLDAddr As String
    Dim strESCAddr As String
    Dim blnLoadDock As Boolean
    blnLoadDock = False
        
    file = Format(Date, "m.d.yy.x\l\sx")
    
    If strType = "Cell" Then
        If strAddr = "$D$3" Then
            strLDAddr = "B" & strColRow
        
        End If
    
        If strColor = "64636" Then
            If Not strLDAddr = vbNullString Then
                Workbooks(file).Worksheets("Esc-Gum-LD").Range(F29) = "c"
                Workbooks(file).Worksheets("Esc-Gum-LD").Range(strLDAddr).Offset(0, 1) = "h"
            ElseIf Not strESCAddr = vbNullString Then
                Workbooks(file).Worksheets("Esc-Gum-LD").Range(strESCAddr) = "o"
            End If
        Else
            If Not strLDAddr = vbNullString Then
                Workbooks(file).Worksheets("Esc-Gum-LD").Range(strLDAddr) = "o"
                Workbooks(file).Worksheets("Esc-Gum-LD").Range(strLDAddr).Offset(0, 1) = "h"
            ElseIf Not strESCAddr = vbNullString Then
                Workbooks(file).Worksheets("Esc-Gum-LD").Range(strESCAddr) = "x"
            End If
        End If
.......
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I'm not dived into debuging the code, but as a quick check, have you tried:

Code:
Workbooks(file).Worksheets("Esc-Gum-LD").Range("F29").Value ="c"

Caleeco
 
Upvote 0
Thanks again for the quick response, but sadly this doesn't work either. Little help anyone?


The variable "file" must be the complete filename of the workbook, including the file extension.

.x\l\sx doesn't look like a valid file extension.
 
Upvote 0
The variable F29 is out of range.
Try adding quote marks

Code:
Workbooks(file).Worksheets("Esc-Gum-LD").Range([B][COLOR="#FF0000"]"[/COLOR][/B]F29[B][COLOR="#FF0000"]"[/COLOR][/B]) = "c"
 
Last edited:
Upvote 0
The variable F29 is out of range.
Try adding quote marks

Code:
Workbooks(file).Worksheets("Esc-Gum-LD").Range([B][COLOR=#FF0000]"[/COLOR][/B]F29[B][COLOR=#FF0000]"[/COLOR][/B]) = "c"
Posts#2 and 4 already suggested this. OP says that doesn't fix the problem.
 
Upvote 0
Then use this and find which line errors

Code:
With Workbooks(file)
    With .Worksheets("Esc_Gum_LD")
        With .Range("F29")
            .Value = "c"
        End With
    End With
End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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