Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Repeating code


Hi, I am trying to repeat the following code (below) 350 times, is there
an easy way to do it, without copying and pasting.



Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
If Target.Address(0, 0) = "H2" Then
Application.EnableEvents = False
With Sheets("Utility")
If Target.Value = "Yes" Then
..[I2].Name = "Thelis"
[I2].Value = "N/A"
[J2].Value = "N/A"
Else
..[A1:A5].Name = "Thelis"
[I2].ClearContents
[J2].ClearContents
End If
End With
Application.EnableEvents = True
End If

If Target.Address(0, 0) = "H3" Then
Application.EnableEvents = False
With Sheets("Utility")
If Target.Value = "Yes" Then
..[I3].Name = "Thelis"
[I3].Value = "N/A"
[J3].Value = "N/A"
Else
..[A1:A5].Name = "Thelis"
[I3].ClearContents
[J3].ClearContents
End If
End With
Application.EnableEvents = True
End If


--
mandeepuppal
------------------------------------------------------------------------
mandeepuppal's Profile: http://www.excelforum.com/member.php...o&userid=36473
View this thread: http://www.excelforum.com/showthread...hreadid=562388

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Repeating code

One way:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim shtUtil As Worksheet
With Target
If .Count 1 Then Exit Sub
If IsEmpty(.Value) Then Exit Sub
If Not Intersect(.Cells, Range("H2:H351")) Is Nothing Then
Set shtUtil = Sheets("Utility")
If .Value = "Yes" Then
shtUtil.Cells(.Row, 9).Name = "Thelis"
Cells(.Row, 9).Resize(1, 2).Value = "N/A"
Else
shtUtil.Range("A1:A5").Name = "Thelis"
Cells(.Row, 9).Resize(1, 2).ClearContents
End If
End If
End With
End Sub




In article ,
mandeepuppal
wrote:

Hi, I am trying to repeat the following code (below) 350 times, is there
an easy way to do it, without copying and pasting.



Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
If Target.Address(0, 0) = "H2" Then
Application.EnableEvents = False
With Sheets("Utility")
If Target.Value = "Yes" Then
.[I2].Name = "Thelis"
[I2].Value = "N/A"
[J2].Value = "N/A"
Else
.[A1:A5].Name = "Thelis"
[I2].ClearContents
[J2].ClearContents
End If
End With
Application.EnableEvents = True
End If

If Target.Address(0, 0) = "H3" Then
Application.EnableEvents = False
With Sheets("Utility")
If Target.Value = "Yes" Then
.[I3].Name = "Thelis"
[I3].Value = "N/A"
[J3].Value = "N/A"
Else
.[A1:A5].Name = "Thelis"
[I3].ClearContents
[J3].ClearContents
End If
End With
Application.EnableEvents = True
End If

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
repeating code in visual basic tobypitblado Excel Discussion (Misc queries) 4 September 17th 08 11:55 AM
Repeating Above Value Roger J Michaud Excel Worksheet Functions 3 December 13th 06 02:37 PM
Repeating some code on all worksheets matpj[_29_] Excel Programming 6 January 12th 06 12:26 PM
Repeating Lynn Excel Worksheet Functions 2 January 7th 05 04:25 PM
Repeating code SiouxieQ Excel Programming 1 November 24th 04 01:09 PM


All times are GMT +1. The time now is 12:22 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"