Xl Script compil error Invalid outside proce

August 5, 2011 at 08:34:10
Specs: Windows 7 Enterprise, Intel Core i5
Hi. I am new with coding. I need help with a particular worksheet.
I have a worksheet where column W (23) for example contains values equal to "AI", "AO", and "Co" using data validation. How can I automatically copy the contents of the row where Column W is equal to "AI" then copy it to the next sheet (6).
Basically what I am trying to do is once for each AI, AO,DO for Sheet,6, 7 and 8. I hope to transfer the active row to the next available row in the next sheet. When I wrote below script I get compoilin error “Invalid outside procedure”. Please help.

My Script:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim nxtRow As Integer
'Determine if change was to Column W (23)
If Target.Column = 23 Then
'If Yes, Determine if cell = AI
If Target.Value = "AI" Then
'If Yes, find next empty row in Sheet 6
nxtRow = Sheets(6).Range("W" & Rows.Count).End(xlUp).Row + 1
'Copy changed row and paste into Sheet Analog Input List
Target.EntireRow.Copy _
Destination:=Sheets(6).Range("A" & nxtRow)
End If
End If
End Sub

See More: Xl Script compil error Invalid outside proce

Report •

August 5, 2011 at 20:11:25
Your code works fine for me.

Before I offer a possible solution, allow me to point out 2 things:

1 - The term Script isn't usually used when discussing VBA code. The more commonly used terms are either a Macro, "VBA code" or simply "code".

2 - Before you post any more code in this forum, please click on the Blue line at the end of this post and read the How To posted there. Thanks!

As far as your error, "Invalid outside procedure" usually means that you have stray line or comment outside of your actual code, i.e. before Private Sub or after End Sub.

The Option Explicit line is fine...that can be outside the macro, but any stray character or string will cause that error since the VBA editor doesn't know what to do with it.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •
Related Solutions

Ask Question