Sheet(“Next”) Cells (A1:A) are populated in an earlier routine
Sheet(“Members”) is a database that has been updated in another routine
Prior to saving the updated project, I wish to add the updated values that exist in Sheet(Members) Column R to all corresponding entries in Sheet(Next) Column B
So:
If Sheet(Next) A1 = "Jones John"
Sheet(Next) B1 = Sheet(Members) “Jones John” iRow 16 value.
Etc…
I have similar code already in my project and thought I knew how to modify it.
But, I’ve been wrestling with this for hours and can’t figure out my error or even if it’s the best solution.
Sheet(“Members”) is a database that has been updated in another routine
Prior to saving the updated project, I wish to add the updated values that exist in Sheet(Members) Column R to all corresponding entries in Sheet(Next) Column B
So:
If Sheet(Next) A1 = "Jones John"
Sheet(Next) B1 = Sheet(Members) “Jones John” iRow 16 value.
Etc…
I have similar code already in my project and thought I knew how to modify it.
But, I’ve been wrestling with this for hours and can’t figure out my error or even if it’s the best solution.
Code:
Const msMembersSheet As String = "Members"
Const msNextSheet As String = "Next"
Dim iCol As Integer
Dim lRow As Long, lRow1 As Long
Dim objNames As Object
Dim rCur As Range
Dim sKey As String
Dim wsMembers As Worksheet, wsNext As Worksheet
Set objNames = Nothing
Set objNames = CreateObject("Scripting.Dictionary")
Set wsNext = Sheets(msNextSheet)
Set wsMembers = Sheets(msMembersSheet)
For Each rCur In Intersect(wsMembers.UsedRange, wsMembers.Columns("C"))
lRow = rCur.Row
If lRow > 1 Then
sKey = Trim$(CStr(rCur.Value))
If sKey <> "" Then
On Error Resume Next
objNames.Add Key:=sKey, Item:=lRow
On Error GoTo 0
End If
End If
Next rCur
iCol = wsNext.Cells(1, Columns.Count).End(xlToLeft).column - 22
For Each rCur In Intersect(wsNext.UsedRange, wsNext.Columns("A"))
lRow = rCur.Row
If lRow > 2 Then
sKey = Trim$(CStr(rCur.Value))
If sKey <> "" Then
lRow1 = 1
On Error Resume Next
lRow1 = objNames.Item(sKey)
On Error GoTo 0
If lRow1 = 0 Then
lRow1 = wsNext.Cells(Rows.Count, "A").End(xlUp).Row ' + 1
wsNext.Range("A" & lRow1).Value = sKey
'objNames.Add Key:=sKey, Item:=lRow1
End If
wsNext.Cells(lRow1, iCol).Value = wsMembers.Range("R" & lRow).Value
End If
End If
Next rCur
objNames.RemoveAll
Set objNames = Nothing