supermom28115
New Member
- Joined
- May 9, 2022
- Messages
- 43
- Office Version
- 365
- Platform
- Windows
I am working with a worksheet where the user enters data and at several places they indicate whether the value in a cell will be the same value as the cell just entered. I was trying to write a worksheet change event code that would check for the target cell (row 20 of any column) value to be equal to yes and if so make the value in cell 21 (same column) equal to cell 19(same column). This is only my 4th or 5th set of code that I have written that has been productive in that something happened. I can not enter anything into my worksheet at all now. It is a new workbook and only has 5 sheets and this sheet has one column of labels and one column of data. It did have 6 columns of data, but stuff happened. Anyway, I tried to debug but it didn't step into the code even after i reset the code. I am sure I have done something wrong that is so simple but I have already spent 6 hours trying to find any reference to dealing with a target range that was an entire row. I found a few that discussed columns but the data and action needed were extremely different than my needs.
I am simply looking for a set of code that will recognize that the cell changed, check for yes (no means do nothing) and make the two cells values the same.
This set of code will be a workhorse in my spreadsheets due to so much of my data is very likely the same, but the data structure for each data type will be different so I will need to be able to repurpose the code in multiple places on the sheet, in the workbook, and in other workbooks.
This is my first post so if I haven't provided the right or enough information I apologize and do appreciate any help you can provide this new vba user.
I am simply looking for a set of code that will recognize that the cell changed, check for yes (no means do nothing) and make the two cells values the same.
This set of code will be a workhorse in my spreadsheets due to so much of my data is very likely the same, but the data structure for each data type will be different so I will need to be able to repurpose the code in multiple places on the sheet, in the workbook, and in other workbooks.
This is my first post so if I haven't provided the right or enough information I apologize and do appreciate any help you can provide this new vba user.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim changed As Range
If Not Intersect(Target, Range("20:20")) Is Nothing Then
Set changed = Target.Address
If changed = "yes" Then
changed.Offset(1, 0).Value = changed.Offset(-1, 0).Value
Application.EnableEvents = False
Target = newinput
Application.EnableEvents = True
End If
End If
End Sub