ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Visual Basic Code (https://www.excelbanter.com/excel-programming/379013-visual-basic-code.html)

amirstal

Visual Basic Code
 
I have this code in my spreadsheet. But I don't want it to include all
the rows that are above row number 10 (just row 10 and all the rows
below it). How can I do it?

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = "$G$10" Then _
Target.Offset(, 2) = Target.Offset(, -2) * Target * (-1)
If Target.Address = "$I$2" Then _
Target.Offset(, -2) = Target / Target.Offset(, -4) * (-1)
Application.EnableEvents = True

If Target.Row < 2 Then Exit Sub
Application.EnableEvents = False
If Target.Column = 7 Then _
Target.Offset(, 2) = Target.Offset(, -2) * Target * (-1)
If Target.Column = 9 Then _
Target.Offset(, -2) = Target / Target.Offset(, -4) * (-1)
Application.EnableEvents = True
End Sub


Thanks.


Dave Peterson

Visual Basic Code
 
It looks like you could change this line:

If Target.Row < 2 Then Exit Sub
to
If Target.Row < 10 Then Exit Sub

amirstal wrote:

I have this code in my spreadsheet. But I don't want it to include all
the rows that are above row number 10 (just row 10 and all the rows
below it). How can I do it?

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = "$G$10" Then _
Target.Offset(, 2) = Target.Offset(, -2) * Target * (-1)
If Target.Address = "$I$2" Then _
Target.Offset(, -2) = Target / Target.Offset(, -4) * (-1)
Application.EnableEvents = True

If Target.Row < 2 Then Exit Sub
Application.EnableEvents = False
If Target.Column = 7 Then _
Target.Offset(, 2) = Target.Offset(, -2) * Target * (-1)
If Target.Column = 9 Then _
Target.Offset(, -2) = Target / Target.Offset(, -4) * (-1)
Application.EnableEvents = True
End Sub

Thanks.


--

Dave Peterson


All times are GMT +1. The time now is 08:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com