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?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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
 
Upvote 0
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:
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,044
Members
448,543
Latest member
MartinLarkin

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
Back
Top