Runtime error 9

sandeep9dec

New Member
Joined
Nov 29, 2014
Messages
13
Hi,
I am very new to the VBA programming in below program i ma receiving the Run time error 9. at red color highlighted place.
can some one help to resolve this issue.

Rich (BB code):
Dim iRow, iCol  As Integer
Dim strColName As String
Dim strColFGCode As String
Dim strColPName As String
Dim strColHLink As String
Dim bValidate As Boolean


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    GetValues (Target.Row)
   
    If Target.Column = 4 And strColHLink = Empty And Target.Row <> 1 Then

        If strColFGCode = Empty Then
                 MsgBox "Empty Row", vbInformation, "FC Code"
                
        Else
                 If IsDuplicate(Target.Row) = True Then
                     MsgBox "Duplicate FC Code exists ! ", vbInformation, "FC Code"
                 Else
                    CreateCopy strColFGCode
                 End If
                 End If
        Else
        If Target.Column = 4 Then
       
    Worksheets(strColFGCode).Activate
    End If
   
    End If

End Sub
Sub GetValues(iRow As Integer)

    rw = Worksheets("INDEX").Rows(iRow)
   
    strColName = rw(1, 1)
    strColFGCode = rw(1, 2)
    strColPName = rw(1, 3)
    strColHLink = rw(1, 4)

End Sub


Sub CreateCopy(FCode As String)

    Sheets("Main").Select
    Sheets("Main").Copy After:=Sheets(Sheets.Count)
    Sheets("Main (2)").Select
    Sheets("Main (2)").Name = FCode
    ActiveWorkbook.Save

   
    Worksheets("INDEX").Activate
   
    ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
        FCode + "!A1", TextToDisplay:="Select " + FCode

End Sub


Function IsDuplicate(iRow As Integer) As Boolean

Set FindRow = Worksheets("INDEX").Range("B:B").Find(What:=strColFGCode, LookIn:=xlValues)

If FindRow.Row = iRow Then
    IsDuplicate = False
Else
    IsDuplicate = True
End If

End Function
Private Sub Worksheet_Activate()
Dim Cell As Range
   With ActiveSheet
   .Protect Password:="Hetvi123"
        'Protect with blank password, you can change it
   End With
End Sub
 
Last edited by a moderator:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
That suggests that the active workbook doesn't have a sheet called MAIN in it.
 
Upvote 0
Hi.
Yeah same as RoryA
If you have named the sheet in vba editor properties you can try using code Main.select instead of Sheets"Main".Select
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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