Copy value if criteria not exist in column

akaseto

New Member
Joined
Oct 10, 2021
Messages
18
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
hi everyone
i hit a big wall today i want to look up value if not exist in the column then copy value form another workbook.

this is my code :
Rich (BB code):
Private Sub kas_awal()
Application.ScreenUpdating = False
    Dim c1 As Range, lastrw As Long
    Dim basepath, N_kas As String
    Dim ws, kas As Worksheet
    Dim dt As Date
   
    basepath = "D:\Documents\LAP\"
    basepath = basepath & Year(Date) & "\lookup.xlsm"
    Set ws = ThisWorkbook.Worksheets("Admin")
    Set kas = Workbooks.Open(basepath).Worksheets("Admin")
    N_kas = "Good"
   
        With CreateObject("scripting.dictionary")
            For Each c1 In ws.Range("C1", ws.Range("C" & Rows.Count).End(xlUp))
                If Not .Exists(N_kas) Then 'if my sheet doesnt contain "Good" in column C then
                    nval = kas.Range("I33").Value ' i want to copy this cell value
                    dt = Format(Date, "dd/mm/yyyy")
                        With ws
                            lastrw = .Cells(.Rows.Count, 1).End(xlUp).Row
                            .Unprotect ("xxx")
                            .Cells(lastrw + 1, 1).Value = dt
                            .Cells(lastrw + 1, 2).Value = "UMT"
                            .Cells(lastrw + 1, 3).Value = "Good"
                            .Cells(lastrw + 1, 4).Value = nval
                        End With
                End If
            Next c1
        End With
    ws.Activate
End Sub
this code work but when i run twice, its still copy the value even "Good" is exists in column and multiple the value from up above :((
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,215,066
Messages
6,122,948
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