Could you check my code please

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
I have a worksheet called SKP IMMO LIST
I am using the code below.

My problem is that after making my selections on the user form i then press the CommandButton1 but a see a run time error9,subscript out of range.
This code is then shown in yellow,
Set wsSKPIMMOLIST = ThisWorkbook.Worksheets("SKPIMMOLIST")

But i dont see why ?

Code:
Private Sub CommandButton1_Click()
    Dim i As Integer
    Dim LastRow As Long
    Dim wsSKPIMMOLIST As Worksheet
    
    Set wsSKPIMMOLIST = ThisWorkbook.Worksheets("SKPIMMOLIST")
    
    For i = 1 To 6
        With Me.Controls("TextBox" & i)
        If .Text = "" Then
        MsgBox Choose(i, "Vehicle", "Year", "Button", _
                                "Chip", "Immo", "Notes") & _
                                " Not Entered", vbCritical, "SKP IMMO LIST"
            .SetFocus
            Exit Sub
        End If
        End With
    Next i




    With wsSKPIMMOLIST
        LastRow = .Cells(.Rows.Count, 2).End(xlUp).Row + 1
    End With
    
    For i = 1 To 6
        With Me.Controls("TextBox" & i)
        wsSKPIMMOLIST.Cells(LastRow, i * 2).Value = .Text
            .Text = ""
        End With
    Next i
    MsgBox "SKP IMMO LIST UPDATED", vbInformation, "SKP IMMO LIST"
    TextBox1.SetFocus
End Sub

The sheet has a space between each word so its like this SKP IMMO LIST
If i put that where its shown in yellow then it makes things even worse etc
So i closed it up thinking the space was the issue but no ??
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Are you sure that you have no leading or trailing spaces in the sheet name?
 
Upvote 0

Forum statistics

Threads
1,214,936
Messages
6,122,340
Members
449,079
Latest member
rocketslinger

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