PLEASE help with VB macro fix????


Posted by nica on January 21, 2002 12:51 PM

Hoping someone can help...
I have a workbook with 2 sheets in it. the first is called Sales & the second is called Survey.
There is a column on Sales that tells me whether
the contact was a sale or a survey. If it was a sale,then the info to input is on the remaining sheet; however, if it was a survey, then info has to be input on the sheet Survey. Can I write some code into the editor that will automatically make the second sheet "Survey" come up from "Sales" if a 's' is entered into a cell in that column? This will ensure that the survey form gets filled out, which many have been forgetting.
I do not have any idea how to type in the VB code - so please(!) be as specific as you can - so I don't have to spend another 6 hours just trying to have the editor take the code.

THANK YOU!!!!!
Nica

Posted by Mark O'Brien on January 21, 2002 1:10 PM

Nica,

I think this code is what you are looking for. I have assumed that the "s" for survey will be typed into column "A". To change this find the line in the code that says:

Set TargetColumn = Me.Range("A:A")

Then change "A:A" to whatever column you need it to be, e.g. for column "B" change it to "B:B"

Follow these steps.

1. Right-click on the name tab of the "Sales" worksheet.
2. Select "View Code" from the pop up menu
3. Copy and paste the following code into the right hand panel of the window that appears.

Here is the code:

Private Sub Worksheet_Change(ByVal Target As Range)
'Declare Variables
Dim TargetColumn As Range
Dim TriggerText As String

'Initialise Variables
Set TargetColumn = Me.Range("A:A") 'This is the column that will contain the "s" for "survey"
TriggerText = "s" 'This is the Text that is used to denote survey

If Target.Column = TargetColumn.Column Then
If LCase(Target.Value) = TriggerText Then
Sheets("Survey").Activate
End If
End If
End Sub 'End of the code

If you have any problems just repost.

Posted by Richard Winfield on January 21, 2002 1:17 PM

The following macro will bring up the survey worksheet anytime the word "Survey" or "survey" is typed into any cell on the sales sheet. To install this open the workbook containing the two sheets and right click on the tab for the "sales" sheet. Choose view code from the menu then paste this macro into the VB editor window.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Target.Value = "Survey" Then
Sheets("Survey").Select
End If
If Target.Value = "survey" Then
Sheets("Survey").Select
End If
Application.ScreenUpdating = True
End Sub

Hope this helps,
Rick

Posted by Richard Winfield on January 21, 2002 1:21 PM

One More thing


Forgot to tell you if you want to change the trigger word merely change the Target.Value word to whatever you want.

Rick

Posted by nica on January 21, 2002 1:32 PM

If Target.Column = TargetColumn.Column Then If LCase(Target.Value) = TriggerText Then Sheets("Survey").Activate End If End If 'End of the code

Mark, you the man!!
Works fine, except when I delete data from cells
in that column(more than one at a time - individually works ok) now, I get a run-time error '13' type mismatch. Have any idea on how
I can prevent this from happening?
Of course, other than this small setback - its works beautifully. I can certainly live without the deletion fix if you don't know what gives.

Thanks again,
nica

Posted by Mark O'Brien on January 21, 2002 2:25 PM

Easy fix, to save explaining where to put code though, just copy and paste this code instead of the original code I gave you:

Private Sub Worksheet_Change(ByVal Target As Range)
'Declare Variables
Dim TargetColumn As Range
Dim TriggerText As String

On Error GoTo ERR_DELETE

'Initialise Variables
Set TargetColumn = Me.Range("A:A") 'This is the column that will contain the "s" for "survey"
TriggerText = "s" 'This is the Text that is used to denote survey

If Target.Column = TargetColumn.Column Then
If LCase(Target.Value) = TriggerText Then
Sheets("Survey").Activate
End If
End If

ERR_DELETE:

End Sub 'end of code

, If Target.Column = TargetColumn.Column Then If LCase(Target.Value) = TriggerText Then Sheets("Survey").Activate End If End If

Posted by nica on January 21, 2002 2:56 PM

If Target.Column = TargetColumn.Column Then If LCase(Target.Value) = TriggerText Then Sheets("Survey").Activate End If End If 'End of the code

Mark, you the man!!
Works fine, except when I delete data from cells
in that column(more than one at a time - individually works ok) now, I get a run-time error '13' type mismatch. Have any idea on how
I can prevent this from happening?
Of course, other than this small setback - its works beautifully. I can certainly live without the deletion fix if you don't know what gives.

Thanks again,
nica

Posted by nica on January 21, 2002 2:57 PM

Thanks Mark!!
I definately owe you one!

nica

Posted by nica on January 22, 2002 8:46 AM

If Target.Column = TargetColumn.Column Then If LCase(Target.Value) = TriggerText Then Sheets("Survey").Activate End If End If If Target.Column = TargetColumn.Column Then If LCase(Target.Value) = TriggerText Then Sheets("Survey").Activate End If End If


MARK,
The fix on the error when I 'delete' more than
one cell in this column is not working. It still flashes over to the sheet as I needed - I just hate to give this out to everyone knowing that when they delete cells simultaniously(as they do) - they will get an error. I this fix working on your System?
Thanks again,
nica



Posted by Mark O'Brien on January 23, 2002 7:34 AM

: On Error GoTo ERR_DELETE If Target.Column = TargetColumn.Column Then If LCase(Target.Value) = TriggerText Then Sheets("Survey").Activate End If End If If Target.Column = TargetColumn.Column Then If LCase(Target.Value) = TriggerText Then Sheets("Survey").Activate End If End If


This fix is working on my system. I've tried every combination I can think of to try to duplicate your error. Could you post again and describe exactly what you are doing and give me a small set of test data that you would use? I've been away from the office or else I would have replied to this sooner.