Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default What is worng with this code?

This code keeps throwing errors. The If statement is in yellow when
the VB window comes up. I have tried putting other code in thre and
it seems to work fine. I do nto knwo if there is an issue due to
adding columns.


Please help.
Thanks,
Jay

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
If Target.Address = "$I$2" And Target.Value = "Inner Box Base"
Then
Columns("K:L").Insert Shift:=xlToRight
Columns("I:J").Copy Destination:=Columns("K:L")
Range("K2") = "Inner Box Lid"
Else
Exit Sub
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default What is worng with this code?

Copy to a range instead. Suggest you limit the source to a range instead of
the entire column. If you want this for ALL worksheets then put in the
ThisWorkbook module. Else put in the sheet module of the sheet desired and
change to

Private Sub Worksheet_Change(ByVal Target As Range)
code here
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Address = "$I$2" And Target.Value = "Inner Box Base" Then
Columns("K:L").Insert Shift:=xlToRight
Columns("I:J").Copy range("k1")
Range("K2") = "Inner Box Lid"
End If
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"jlclyde" wrote in message
...
This code keeps throwing errors. The If statement is in yellow when
the VB window comes up. I have tried putting other code in thre and
it seems to work fine. I do nto knwo if there is an issue due to
adding columns.


Please help.
Thanks,
Jay

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
If Target.Address = "$I$2" And Target.Value = "Inner Box Base"
Then
Columns("K:L").Insert Shift:=xlToRight
Columns("I:J").Copy Destination:=Columns("K:L")
Range("K2") = "Inner Box Lid"
Else
Exit Sub
End If
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,081
Default What is worng with this code?

try

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$I$2" And Target.Value = "Inner Box Base" Then
Application.EnableEvents = False
Columns("K:L").Insert Shift:=xlToRight
Columns("I:J").Copy Destination:=Columns("K:L")
Range("K2") = "Inner Box Lid"
Application.EnableEvents = True
Else
Exit Sub
End If

End Sub



"jlclyde" wrote:

This code keeps throwing errors. The If statement is in yellow when
the VB window comes up. I have tried putting other code in thre and
it seems to work fine. I do nto knwo if there is an issue due to
adding columns.


Please help.
Thanks,
Jay

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
If Target.Address = "$I$2" And Target.Value = "Inner Box Base"
Then
Columns("K:L").Insert Shift:=xlToRight
Columns("I:J").Copy Destination:=Columns("K:L")
Range("K2") = "Inner Box Lid"
Else
Exit Sub
End If
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default What is worng with this code?

On Aug 27, 2:37*pm, "Don Guillett" wrote:
Copy to a range instead. Suggest you limit the source to a range instead of
the entire column. If you want this for ALL worksheets then put in the
ThisWorkbook module. Else put in the sheet module of the sheet desired and
change to

Private Sub Worksheet_Change(ByVal Target As Range)
code here
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Count 1 Then Exit Sub
*If Target.Address = "$I$2" And Target.Value = "Inner Box Base" Then
* Columns("K:L").Insert Shift:=xlToRight
* Columns("I:J").Copy range("k1")
* Range("K2") = "Inner Box Lid"
End If
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"jlclyde" wrote in message

...



This code keeps throwing errors. *The If statement is in yellow when
the VB window comes up. *I have tried putting other code in thre and
it seems to work fine. *I do nto knwo if there is an issue due to
adding columns.


Please help.
Thanks,
Jay


Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
* *If Target.Address = "$I$2" And Target.Value = "Inner Box Base"
Then
* * * *Columns("K:L").Insert Shift:=xlToRight
* * * *Columns("I:J").Copy Destination:=Columns("K:L")
* * * *Range("K2") = "Inner Box Lid"
* *Else
* * * *Exit Sub
* *End If
End Sub- Hide quoted text -


- Show quoted text -


Both of these soutions work, but Don's was a little less typing.
thanks for the fast responce.
Jay
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
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
What is worng with my formula? robert morris Excel Discussion (Misc queries) 21 August 28th 07 10:47 PM
Convert a Number Code to a Text Code Traye Excel Discussion (Misc queries) 3 April 6th 07 09:54 PM
Unprotect Code Module in Code Damien Excel Discussion (Misc queries) 2 April 18th 06 03:10 PM
copying vba code to a standard code module 1vagrowr Excel Discussion (Misc queries) 2 November 23rd 05 04:00 PM


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

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

About Us

"It's about Microsoft Excel"