Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Subscript out of Range

I am getting an error on Set removeRef line. The error state Subscript out
of Range, why is this?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Cancel = True
On Error GoTo LineExit 'if Quote sheet is blank it ignores error
Target = ActiveCell
On Error GoTo 0

Dim myRef As Range
Dim removeRef As Range
Dim LastRow As Long
Dim FirstRow As Long
Dim SelectRow As Long


'procedure if "Remove" is double clicked
If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub

Application.ScreenUpdating = False

Select Case Left(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'finds reference number that is above the "Remove" that was clicked
Set removeRef =
Sheets(sh).Rows(1).Find(What:=Target.Offset(-3).Value, _
After:=Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

'clears the particular product data that is stored in the plastic faces
worksheet
Sheets("QUOTE").Unprotect Password:="AdTech"
Sheets(sh).Unprotect Password:="AdTech"

'MY CODE CONTINUES...................

Thanks,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Subscript out of Range

Unless your ActiveSheet happens to be either "Plastic Faces" or "Extruded
Cabinets" It won't find the value of "Target.Offset(-3)" since that was on
the ActiveSheet. What you need to do is set that value to a variable and
then use the variable in the find statement.

"RyanH" wrote:

I am getting an error on Set removeRef line. The error state Subscript out
of Range, why is this?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Cancel = True
On Error GoTo LineExit 'if Quote sheet is blank it ignores error
Target = ActiveCell
On Error GoTo 0

Dim myRef As Range
Dim removeRef As Range
Dim LastRow As Long
Dim FirstRow As Long
Dim SelectRow As Long


'procedure if "Remove" is double clicked
If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub

Application.ScreenUpdating = False

Select Case Left(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'finds reference number that is above the "Remove" that was clicked
Set removeRef =
Sheets(sh).Rows(1).Find(What:=Target.Offset(-3).Value, _
After:=Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

'clears the particular product data that is stored in the plastic faces
worksheet
Sheets("QUOTE").Unprotect Password:="AdTech"
Sheets(sh).Unprotect Password:="AdTech"

'MY CODE CONTINUES...................

Thanks,
Ryan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Subscript out of Range

I'd change this portion:
After:=Cells(1), _
to
After:=Sheets(sh).Cells(1), _

Unqualified ranges in the worksheet module will refer to the sheet owning the
code--probably not what you wanted.

RyanH wrote:

I am getting an error on Set removeRef line. The error state Subscript out
of Range, why is this?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Cancel = True
On Error GoTo LineExit 'if Quote sheet is blank it ignores error
Target = ActiveCell
On Error GoTo 0

Dim myRef As Range
Dim removeRef As Range
Dim LastRow As Long
Dim FirstRow As Long
Dim SelectRow As Long

'procedure if "Remove" is double clicked
If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub

Application.ScreenUpdating = False

Select Case Left(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'finds reference number that is above the "Remove" that was clicked
Set removeRef =
Sheets(sh).Rows(1).Find(What:=Target.Offset(-3).Value, _
After:=Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

'clears the particular product data that is stored in the plastic faces
worksheet
Sheets("QUOTE").Unprotect Password:="AdTech"
Sheets(sh).Unprotect Password:="AdTech"

'MY CODE CONTINUES...................

Thanks,
Ryan


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Subscript out of Range

Thanks for your responses. I am getting a Type Mismatch Error. Forgive me I
am new to VBA. I am still trying to learn the errors, because I get a lot of
them, lol.

My goal here is to double click on a Reference Number (Target) and my code
should extract the first to letters of the reference number. These first two
letters will tell the code what worksheet the reference number will be found.
At that point it will edit data or clear data. Here is the first portion of
my code, which still contains the error.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Cancel = True
On Error GoTo LineExit 'if Quote sheet is blank it ignores error
Target = ActiveCell
On Error GoTo 0

Dim removeRef As Range
Dim sh As Worksheet
Dim FirstRow As Long
Dim LastRow As Long
Dim myRef As Range

'procedure if "Remove" is double clicked
If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub

Application.ScreenUpdating = False

Select Case Left(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'finds reference number that is above the "Remove" that was clicked
Set removeRef =
Sheets(sh).Rows(1).Find(What:=Target.Offset(-3).Value, _
After:=Sheets(sh).Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

'clears the particular product data that is stored in the plastic faces
worksheet
Sheets("QUOTE").Unprotect Password:="AdTech"
Sheets(sh).Unprotect Password:="AdTech"

With Sheets(sh).Range(removeRef.Address)
.EntireColumn.ClearContents
.Offset(0, 2).EntireColumn.ClearContents
End With

'code continues from here........

Thanks again Ryan

"Dave Peterson" wrote:

I'd change this portion:
After:=Cells(1), _
to
After:=Sheets(sh).Cells(1), _

Unqualified ranges in the worksheet module will refer to the sheet owning the
code--probably not what you wanted.

RyanH wrote:

I am getting an error on Set removeRef line. The error state Subscript out
of Range, why is this?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Cancel = True
On Error GoTo LineExit 'if Quote sheet is blank it ignores error
Target = ActiveCell
On Error GoTo 0

Dim myRef As Range
Dim removeRef As Range
Dim LastRow As Long
Dim FirstRow As Long
Dim SelectRow As Long

'procedure if "Remove" is double clicked
If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub

Application.ScreenUpdating = False

Select Case Left(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'finds reference number that is above the "Remove" that was clicked
Set removeRef =
Sheets(sh).Rows(1).Find(What:=Target.Offset(-3).Value, _
After:=Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

'clears the particular product data that is stored in the plastic faces
worksheet
Sheets("QUOTE").Unprotect Password:="AdTech"
Sheets(sh).Unprotect Password:="AdTech"

'MY CODE CONTINUES...................

Thanks,
Ryan


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Subscript out of Range

Hi Ryan, I guess I wasn't very clear before. Here is a modification to your
code.

If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub
myVar = Target.Offset(-3, 0).Value

Application.ScreenUpdating = False

Select Case Left(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'finds reference number that is above the "Remove" that was clicked
Set removeRef =
Sheets(sh).Rows(1).Find(What:=myVar, _
After:=Sheets(sh).Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

Notice the myVar line. It sets the offset range value to a variable, which
is then used in the Find statement. You need to do this since you are using
a case statement to determine which sheet you are going to search, and the
selected sheet probably will not be the one with the offset range in it. The
myVar variable will be the same no matter which sheet is selected, whereas
the Target.Offset(-3) reference only applied to the original ActiveSheet
value. When you go to a new sheet to Find a value of Target.Offset(-3), it
don't know where the Target is. Hope this helps.

"RyanH" wrote:

Thanks for your responses. I am getting a Type Mismatch Error. Forgive me I
am new to VBA. I am still trying to learn the errors, because I get a lot of
them, lol.

My goal here is to double click on a Reference Number (Target) and my code
should extract the first to letters of the reference number. These first two
letters will tell the code what worksheet the reference number will be found.
At that point it will edit data or clear data. Here is the first portion of
my code, which still contains the error.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Cancel = True
On Error GoTo LineExit 'if Quote sheet is blank it ignores error
Target = ActiveCell
On Error GoTo 0

Dim removeRef As Range
Dim sh As Worksheet
Dim FirstRow As Long
Dim LastRow As Long
Dim myRef As Range

'procedure if "Remove" is double clicked
If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub

Application.ScreenUpdating = False

Select Case Left(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'finds reference number that is above the "Remove" that was clicked
Set removeRef =
Sheets(sh).Rows(1).Find(What:=Target.Offset(-3).Value, _
After:=Sheets(sh).Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

'clears the particular product data that is stored in the plastic faces
worksheet
Sheets("QUOTE").Unprotect Password:="AdTech"
Sheets(sh).Unprotect Password:="AdTech"

With Sheets(sh).Range(removeRef.Address)
.EntireColumn.ClearContents
.Offset(0, 2).EntireColumn.ClearContents
End With

'code continues from here........

Thanks again Ryan

"Dave Peterson" wrote:

I'd change this portion:
After:=Cells(1), _
to
After:=Sheets(sh).Cells(1), _

Unqualified ranges in the worksheet module will refer to the sheet owning the
code--probably not what you wanted.

RyanH wrote:

I am getting an error on Set removeRef line. The error state Subscript out
of Range, why is this?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Cancel = True
On Error GoTo LineExit 'if Quote sheet is blank it ignores error
Target = ActiveCell
On Error GoTo 0

Dim myRef As Range
Dim removeRef As Range
Dim LastRow As Long
Dim FirstRow As Long
Dim SelectRow As Long

'procedure if "Remove" is double clicked
If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub

Application.ScreenUpdating = False

Select Case Left(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'finds reference number that is above the "Remove" that was clicked
Set removeRef =
Sheets(sh).Rows(1).Find(What:=Target.Offset(-3).Value, _
After:=Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

'clears the particular product data that is stored in the plastic faces
worksheet
Sheets("QUOTE").Unprotect Password:="AdTech"
Sheets(sh).Unprotect Password:="AdTech"

'MY CODE CONTINUES...................

Thanks,
Ryan


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Subscript out of Range

Thanks again for getting back with me. Your explanation made sense, but I am
still getting a Type Mismatch Error. Does the error have something to do
with the sh variable? Should I Dim myVar as String and Dim sh as Worksheet?

Thanks
Ryan

"JLGWhiz" wrote:

Hi Ryan, I guess I wasn't very clear before. Here is a modification to your
code.

If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub
myVar = Target.Offset(-3, 0).Value

Application.ScreenUpdating = False

Select Case Left(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'finds reference number that is above the "Remove" that was clicked
Set removeRef =
Sheets(sh).Rows(1).Find(What:=myVar, _
After:=Sheets(sh).Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

Notice the myVar line. It sets the offset range value to a variable, which
is then used in the Find statement. You need to do this since you are using
a case statement to determine which sheet you are going to search, and the
selected sheet probably will not be the one with the offset range in it. The
myVar variable will be the same no matter which sheet is selected, whereas
the Target.Offset(-3) reference only applied to the original ActiveSheet
value. When you go to a new sheet to Find a value of Target.Offset(-3), it
don't know where the Target is. Hope this helps.

"RyanH" wrote:

Thanks for your responses. I am getting a Type Mismatch Error. Forgive me I
am new to VBA. I am still trying to learn the errors, because I get a lot of
them, lol.

My goal here is to double click on a Reference Number (Target) and my code
should extract the first to letters of the reference number. These first two
letters will tell the code what worksheet the reference number will be found.
At that point it will edit data or clear data. Here is the first portion of
my code, which still contains the error.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Cancel = True
On Error GoTo LineExit 'if Quote sheet is blank it ignores error
Target = ActiveCell
On Error GoTo 0

Dim removeRef As Range
Dim sh As Worksheet
Dim FirstRow As Long
Dim LastRow As Long
Dim myRef As Range

'procedure if "Remove" is double clicked
If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub

Application.ScreenUpdating = False

Select Case Left(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'finds reference number that is above the "Remove" that was clicked
Set removeRef =
Sheets(sh).Rows(1).Find(What:=Target.Offset(-3).Value, _
After:=Sheets(sh).Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

'clears the particular product data that is stored in the plastic faces
worksheet
Sheets("QUOTE").Unprotect Password:="AdTech"
Sheets(sh).Unprotect Password:="AdTech"

With Sheets(sh).Range(removeRef.Address)
.EntireColumn.ClearContents
.Offset(0, 2).EntireColumn.ClearContents
End With

'code continues from here........

Thanks again Ryan

"Dave Peterson" wrote:

I'd change this portion:
After:=Cells(1), _
to
After:=Sheets(sh).Cells(1), _

Unqualified ranges in the worksheet module will refer to the sheet owning the
code--probably not what you wanted.

RyanH wrote:

I am getting an error on Set removeRef line. The error state Subscript out
of Range, why is this?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Cancel = True
On Error GoTo LineExit 'if Quote sheet is blank it ignores error
Target = ActiveCell
On Error GoTo 0

Dim myRef As Range
Dim removeRef As Range
Dim LastRow As Long
Dim FirstRow As Long
Dim SelectRow As Long

'procedure if "Remove" is double clicked
If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub

Application.ScreenUpdating = False

Select Case Left(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'finds reference number that is above the "Remove" that was clicked
Set removeRef =
Sheets(sh).Rows(1).Find(What:=Target.Offset(-3).Value, _
After:=Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

'clears the particular product data that is stored in the plastic faces
worksheet
Sheets("QUOTE").Unprotect Password:="AdTech"
Sheets(sh).Unprotect Password:="AdTech"

'MY CODE CONTINUES...................

Thanks,
Ryan

--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Subscript out of Range

Time to post your current code and the indicate the line that causes the error.

Maybe it's a problem when you set your sh variable.

I'd still add code to avoid case differences (PF < pF < Pf < pf) (same with
the Remove check, but I'm repeating myself).

And I'd add a check like:
....
case else
sh = ""
End Select

if sh = "" then
msgbox "not a valid pfx"
else
'do the find
end if




RyanH wrote:

Thanks again for getting back with me. Your explanation made sense, but I am
still getting a Type Mismatch Error. Does the error have something to do
with the sh variable? Should I Dim myVar as String and Dim sh as Worksheet?

Thanks
Ryan

"JLGWhiz" wrote:

Hi Ryan, I guess I wasn't very clear before. Here is a modification to your
code.

If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub
myVar = Target.Offset(-3, 0).Value

Application.ScreenUpdating = False

Select Case Left(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'finds reference number that is above the "Remove" that was clicked
Set removeRef =
Sheets(sh).Rows(1).Find(What:=myVar, _
After:=Sheets(sh).Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

Notice the myVar line. It sets the offset range value to a variable, which
is then used in the Find statement. You need to do this since you are using
a case statement to determine which sheet you are going to search, and the
selected sheet probably will not be the one with the offset range in it. The
myVar variable will be the same no matter which sheet is selected, whereas
the Target.Offset(-3) reference only applied to the original ActiveSheet
value. When you go to a new sheet to Find a value of Target.Offset(-3), it
don't know where the Target is. Hope this helps.

"RyanH" wrote:

Thanks for your responses. I am getting a Type Mismatch Error. Forgive me I
am new to VBA. I am still trying to learn the errors, because I get a lot of
them, lol.

My goal here is to double click on a Reference Number (Target) and my code
should extract the first to letters of the reference number. These first two
letters will tell the code what worksheet the reference number will be found.
At that point it will edit data or clear data. Here is the first portion of
my code, which still contains the error.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Cancel = True
On Error GoTo LineExit 'if Quote sheet is blank it ignores error
Target = ActiveCell
On Error GoTo 0

Dim removeRef As Range
Dim sh As Worksheet
Dim FirstRow As Long
Dim LastRow As Long
Dim myRef As Range

'procedure if "Remove" is double clicked
If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub

Application.ScreenUpdating = False

Select Case Left(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'finds reference number that is above the "Remove" that was clicked
Set removeRef =
Sheets(sh).Rows(1).Find(What:=Target.Offset(-3).Value, _
After:=Sheets(sh).Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

'clears the particular product data that is stored in the plastic faces
worksheet
Sheets("QUOTE").Unprotect Password:="AdTech"
Sheets(sh).Unprotect Password:="AdTech"

With Sheets(sh).Range(removeRef.Address)
.EntireColumn.ClearContents
.Offset(0, 2).EntireColumn.ClearContents
End With

'code continues from here........

Thanks again Ryan

"Dave Peterson" wrote:

I'd change this portion:
After:=Cells(1), _
to
After:=Sheets(sh).Cells(1), _

Unqualified ranges in the worksheet module will refer to the sheet owning the
code--probably not what you wanted.

RyanH wrote:

I am getting an error on Set removeRef line. The error state Subscript out
of Range, why is this?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Cancel = True
On Error GoTo LineExit 'if Quote sheet is blank it ignores error
Target = ActiveCell
On Error GoTo 0

Dim myRef As Range
Dim removeRef As Range
Dim LastRow As Long
Dim FirstRow As Long
Dim SelectRow As Long

'procedure if "Remove" is double clicked
If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub

Application.ScreenUpdating = False

Select Case Left(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'finds reference number that is above the "Remove" that was clicked
Set removeRef =
Sheets(sh).Rows(1).Find(What:=Target.Offset(-3).Value, _
After:=Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

'clears the particular product data that is stored in the plastic faces
worksheet
Sheets("QUOTE").Unprotect Password:="AdTech"
Sheets(sh).Unprotect Password:="AdTech"

'MY CODE CONTINUES...................

Thanks,
Ryan

--

Dave Peterson


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Subscript out of Range

You sure about this statement.

Try adding
msgbox target.offset(-3).value
before and after the find.

I see no reason why that portion of the code is the problem.

JLGWhiz wrote:

<<snipped

Notice the myVar line. It sets the offset range value to a variable, which
is then used in the Find statement. You need to do this since you are using
a case statement to determine which sheet you are going to search, and the
selected sheet probably will not be the one with the offset range in it. The
myVar variable will be the same no matter which sheet is selected, whereas
the Target.Offset(-3) reference only applied to the original ActiveSheet
value. When you go to a new sheet to Find a value of Target.Offset(-3), it
don't know where the Target is. Hope this helps.

"RyanH" wrote:

<<snipped
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Subscript out of Range

The current code is posted below. I just posted the beginning portion of the
code because the entire code is pretty long. The Type Mismatch Error is
highlighted at the Set removeRef variable. This code is placed in Sheet1.

The first two letters will always be capitalized. When I initalize the
UserForm it adds the Two Letters to the time stamp. For example, when the
Plastic Faces UserForm is intialized the Reference Number is "PF" & Date &
Time.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Cancel = True
On Error GoTo LineExit 'if Quote sheet is blank it ignores error
Target = ActiveCell
On Error GoTo 0

Dim removeRef As Range
Dim sh As Worksheet
'Dim myVar As String
Dim FirstRow As Long
Dim LastRow As Long
Dim myRef As Range

'procedure if "Remove" is double clicked
If Target.Value = "Remove" Then
Response = MsgBox("Are you sure you want to remove " &
Target.Offset(-3).Text & " from the quote sheet?", vbOKCancel, "Remove
Product")
If Response < vbOK Then Exit Sub

Application.ScreenUpdating = False

'uses the first two letters of the reference number and tells what worksheet
to find it in
Select Case Left$(Target.Value, 2)
Case Is = "PF"
sh = "Plastic Faces"
Case Is = "EC"
sh = "Extruded Cabinets"
End Select

'reference number to find
myVar = Target.Offset(-3, 0).Value
MsgBox (myVar)

'finds reference number that is above the "Remove" that was clicked
ERROR== Set removeRef = Sheets(sh).Rows(1).Find(What:=myVar, _
After:=Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

'clears the particular product data that is stored in the plastic faces
worksheet
Sheets("QUOTE").Unprotect Password:="AdTech"
Sheets(sh).Unprotect Password:="AdTech"

With Sheets(sh).Range(removeRef.Address)
.EntireColumn.ClearContents
.Offset(0, 2).EntireColumn.ClearContents
End With

'removes data that was requested to be removed from the quote sheet

FirstRow = Range("B" & (ActiveCell.Row - 1)).End(xlUp).Row
LastRow = Range("E" & (ActiveCell.Row + 1)).End(xlDown).Row
LastRow = LastRow - 1
If LastRow = (Rows.Count - 1) Then
LastRow = Range("C" & Rows.Count).End(xlUp).Row
End If
Rows(FirstRow & ":" & LastRow).Delete

'CODE CONTINUES.............

Thanks,Ryan


"Dave Peterson" wrote:

You sure about this statement.

Try adding
msgbox target.offset(-3).value
before and after the find.

I see no reason why that portion of the code is the problem.

JLGWhiz wrote:

<<snipped

Notice the myVar line. It sets the offset range value to a variable, which
is then used in the Find statement. You need to do this since you are using
a case statement to determine which sheet you are going to search, and the
selected sheet probably will not be the one with the offset range in it. The
myVar variable will be the same no matter which sheet is selected, whereas
the Target.Offset(-3) reference only applied to the original ActiveSheet
value. When you go to a new sheet to Find a value of Target.Offset(-3), it
don't know where the Target is. Hope this helps.

"RyanH" wrote:

<<snipped

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
9: Subscript out of range jenz21985 Excel Discussion (Misc queries) 6 May 5th 06 03:36 PM
Subscript out of Range Jon[_22_] Excel Programming 4 April 6th 06 11:24 PM
Subscript out of range Bruce001[_6_] Excel Programming 2 December 2nd 05 04:21 PM
Subscript out of range teresa Excel Programming 1 December 14th 04 09:56 PM
Subscript out of range Ed Excel Programming 1 February 5th 04 07:17 PM


All times are GMT +1. The time now is 02:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"