Fine tune sub worksheet_change

jsjoblom

New Member
Joined
Dec 4, 2009
Messages
37
This sub worksheet_change works(i'm sure it could be better but it works)

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$I$10" Then
If Range("I10").Value = "Yes" Then
Range("B10").Select
Selection.Copy
Range("B11").Select
ActiveSheet.Paste
End If
If Range("I10").Value = "No" Then
Range("B11").Value = ""
End If
End If
End Sub
I need to repeat this in 100 rows. The user has completed row B10 and is now in row B11. If he chooses yes again (target should now be I11)it will copy B11 and place it into B12. etc,etc,
Can anyone help?
 

Some videos you may like

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("I1:I100")) Is Nothing Then Exit Sub
Application.EnableEvents = False
If Target.Value = "Yes" Then
    Target.Offset(, -7).Copy Destination:=Target.Offset(1, -7)
Else
    Target.Offset(1, -7).ClearContents
End If
Application.EnableEvents = True
End Sub
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range
Dim C As Range
Set MyRange = Intersect(Target, Range("I10:I109"))
If Not MyRange is Nothing Then
    For Each C in MyRange
        If C.Value = "Yes" Then
            Range("B"  C.Row).Copy Destination:=Range("B" & C.Row +1)
        ElseIf C.Value = "No" Then
            Range("B" & C.Row +1) = ""
        End if
    Next C
End If
End Sub
 
Last edited:

snb_

Well-known Member
Joined
Nov 9, 2009
Messages
567
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("I1:I100")) Is Nothing Then
    Application.EnableEvents = False
    Target.offset(1,-7)=iif(target="Yes",target.offset(,-7),"")
    Application.EnableEvents = True
  End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,315
Members
414,053
Latest member
Dual Showman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top