VBA Vlookup only if cell in blank

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello all

I am trying to do the following

If the cell range "K" is blank complete a Vlookup
If the cell range "K" has data in do not perform a Vlookup so that the data remains in the cell, any help on this would be great please.

Code:
With Range("K1:K" & LastRow)
        .FormulaR1C1 = "=VLOOKUP(RC[-10],Data!C[-10]:C[3],14,FALSE)"
        .Value = .Value
    End With

This is some code that two of our Excel forum members helped me with for another issue which is similar but works on the cell in the sheet called "Data" being blank and I have tried to modify this

Code:
With Sheets("Data")
        arr = .Cells(1, 1).Resize(.Cells(.Rows.Count, 1).End(xlUp).Row, 14).Value
    End With
    
    For x = LBound(arr, 1) To UBound(arr, 1)
        dic(arr(x, 1)) = arr(x, 14)
    Next x
    
    With Sheets("Comments")
        arr = .Cells(1, 1).Resize(.Cells(.Rows.Count, 1).End(xlUp).Row, 11).Value
        For x = LBound(arr, 1) To UBound(arr, 1)
            If dic.exists(arr(x, 1)) Then arr(x, 11) = dic(arr(x, 1))
        Next x
        
        .Cells(1, 11).Resize(UBound(arr)).Value = Application.Index(arr, 0, 11)
    End With
 
Glad to help & thanks for the feedback
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Not sure if I use this existing thread or start a new one but I still seem to have a problem with this code working correctly.

What I am trying to do is look in the sheet "Comments" in column "K" and if the cell is blank complete the Vlookup from the Data sheet, if the cell in column "K"has a value Stop, do not complete the vlookup and leave the existing data.

at the moment this is overwriting the data

Code:
With Sheets("Data")
        arr = .Cells(1, 1).Resize(.Cells(.Rows.Count, 1).End(xlUp).Row, 14).Value
    End With
    
    For x = LBound(arr, 1) To UBound(arr, 1)
        dic(arr(x, 1)) = arr(x, 14)
    Next x

    With Sheets("Comments")
        arr = .Cells(1, 1).Resize(.Cells(.Rows.Count, 1).End(xlUp).Row, 11).Value
        For x = LBound(arr, 1) To UBound(arr, 1)
        If dic.exists(arr(x, 1)) Then arr(x, 11) = CLng(dic(arr(x, 1)))
        Next x
   
  .Cells(1, 11).Resize(UBound(arr)).Value = Application.Index(arr, 0, 11)
   
End With
 
Upvote 0
There seem to be a bit missing
Code:
With Sheets("Comments")
    arr = .Cells(1, 1).Resize(.Cells(.Rows.Count, 1).End(xlUp).Row, 11).Value
    For x = LBound(arr, 1) To UBound(arr, 1)
        If arr(x, 11) = "" Then
           If dic.exists(arr(x, 1)) Then arr(x, 11) = CLng(dic(arr(x, 1)))
        End If
    Next x
    
    .Cells(1, 11).Resize(UBound(arr)).Value = Application.Index(arr, 0, 11)
End With
 
Upvote 0
probably my fault not yours, as that part was missing from my post#9
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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