Help with code to copy value if criteria is met

Status
Not open for further replies.

joyrichter

New Member
Joined
Jun 17, 2023
Messages
31
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Good day

Thank you for your help with the above code, I am trying to tweek the code bit so that the value on the closing stock under column I is also copied to the recon sheet when the code is run, but for some reason the first 5 lines do not copy over to the recon sheet.

I tweeked the code as follows:
Sub CopyRow()
Application.ScreenUpdating = False
Dim srcWS As Worksheet, desWS As Worksheet, ws1 As Worksheet, ws2 As Worksheet
Dim v1 As Variant, v2 As Variant, v3 As Variant, dic As Object, i As Long, ii As Long
Set srcWS = Sheets("NonMovingStock")
Set desWS = Sheets("Recon")
Set ws1 = Sheets("ClosingStock") 'delete trailing space
Set ws2 = Sheets("GRN") 'delete trailing space
v1 = srcWS.Range("A5", srcWS.Range("A" & Rows.Count).End(xlUp)).Value
v2 = ws1.Range("C2", ws1.Range("C" & Rows.Count).End(xlUp)).Value
v3 = ws2.Range("I1", ws2.Range("I" & Rows.Count).End(xlUp)).Value
Set dic = CreateObject("Scripting.Dictionary")
For i = LBound(v1) To UBound(v1)
If Not dic.exists(v1(i, 1)) Then
dic.Add v1(i, 1), i + 4
End If
Next i
For i = LBound(v2) To UBound(v2)
If dic.exists(v2(i, 1)) Then
For ii = LBound(v3) To UBound(v3)
If dic.exists(v2(i, 1)) Then
desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1).Resize(, 7).Value = ws1.Range("C" & dic(v2(i, 1))).Resize(, 7).Value
Exit For
End If
Next ii
End If
Next i
Application.ScreenUpdating = True
End Sub



Can you please help me with this issue.

Thank you
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Status
Not open for further replies.

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,095
Latest member
nmaske

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