Hi all:
I have this bit of code for adding a Row alphabetically into a Contacts sheet. Works great.
I would like the code to look at the Company Name just added and look one cell above to determine if it matches. If it does, it should copy the data in the cells above to the blank cells just added. If not, do nothing more.
For instance, if D2 was just added via the above code, it should look at D1, determine if it's an exact match and if so copy, say, Range F1:G1 to F2:G2. (I'll set up the exact Range.)
<tbody>
</tbody>
Thanks,
LBinGA
I have this bit of code for adding a Row alphabetically into a Contacts sheet. Works great.
Code:
Sub InsertCompany()Dim sNewName As String
Dim lPosition As Long
Dim rEmpList As Range
Set rEmpList = Range("D1:D1000")
sNewName = InputBox("Enter Name of Company for added Contact")
On Error Resume Next 'if employee needs to go at start of list, Match will return [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=NA]#NA[/URL]
lPosition = Application.WorksheetFunction.Match(sNewName, rEmpList, 1)
On Error GoTo 0 'revert to normal error handling (crashing)
rEmpList(lPosition + 1).Insert
rEmpList(lPosition + 1).Value = sNewName
rEmpList(lPosition + 1).Activate
End Sub
I would like the code to look at the Company Name just added and look one cell above to determine if it matches. If it does, it should copy the data in the cells above to the blank cells just added. If not, do nothing more.
For instance, if D2 was just added via the above code, it should look at D1, determine if it's an exact match and if so copy, say, Range F1:G1 to F2:G2. (I'll set up the exact Range.)
Column D | Column E | Column F | Column G | |
Row 1 | Joe Smith | 2 | 3 | 4 |
Row 2 | Joe Smith | 3 | 4 | |
Row 3 | Jane Doe | 6 | 7 | 8 |
Row 4 | Scooby Doo | 10 | 11 | 12 |
<tbody>
</tbody>
Thanks,
LBinGA