Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
9: Subscript out of range | Excel Discussion (Misc queries) | |||
Subscript out of Range | Excel Programming | |||
Subscript out of range | Excel Programming | |||
Subscript out of range | Excel Programming | |||
Subscript out of range | Excel Programming |