vlookup overwrite current value

SAM MADZLAN

New Member
Joined
Feb 20, 2018
Messages
4
Hi All,

I have 1 filtered data that already been processed(1st set). with my 2nd set code, it overwrites current(1st set) value. Is there any way to make my code only process visible cell.

1st set
Code:
Sub LookMAL1()
Dim x As String
Dim LastRow As Long


LastRow = Range("D" & Rows.Count).End(xlUp).Row
Range("M2").FormulaR1C1 = _
"=VLOOKUP(RC[-1],'MAL1'!C2:C8,7,0)"
Range("M2").Copy Range("M3:M" & LastRow)
        
Range("N2").FormulaR1C1 = _
"=VLOOKUP(RC[-2],'MAL1'!C2:C9,8,0)"
Range("N2").Copy Range("N3:N" & LastRow)
End Sub




2nd set
Code:
Sub LookMAL6()


Dim LastRow As Long


LastRow = Range("D" & Rows.Count).End(xlUp).Row
Range("M2").FormulaR1C1 = _
"=VLOOKUP(RC[-1],'MAL6'!C2:C8,7,0)"
Range("M2").Copy Range("M3:M" & LastRow)
        
Range("N2").FormulaR1C1 = _
"=VLOOKUP(RC[-2],'MAL6'!C2:C9,8,0)"
Range("N2").Copy Range("N3:N" & LastRow)


End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hello,

Sorry but cannot see the difference between what you are calling ' 1st set ' and ' 2nd set ' ...?
 
Upvote 0
If it's the activesheet that has been filtered, try
Code:
Sub LookMAL6()


Dim LastRow As Long
Dim Cl As Range

LastRow = Range("D" & Rows.Count).End(xlUp).Row
For Each Cl In Range("M2:M" & LastRow).SpecialCells(xlVisible)
   Cl.FormulaR1C1 = "=VLOOKUP(RC[-1],'MAL6'!C2:C8,7,0)"
   Cl.Offset(, 1).FormulaR1C1 = "=VLOOKUP(RC[-2],'MAL6'!C2:C9,8,0)"
Next Cl

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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