Horizontally Merged cells give error while using Vlookup Function in EXCEL VBA

Hello All,

I am using the below Vlookup code with a For loop so that the vlookup runs until it reaches last row in my excel sheet.But it gives error when the for loop reaches a merged cells(Horizontally merged cell). Can someone help me in skipping the merged cells ?

Dim LastRowG As Double, dealer As Variant, DealerNumber As Variant, f As Double
        With Balance.Sheets("Líquidas")
           LastRowG = .Cells(.Rows.Count, "A").End(xlUp).Row
        End With

For f = 7 To LastRowG
        dealer = Balance.Sheets("Líquidas").Range("C" & f).Value
 'Checking when the column which is being compared is not empty
        If Not IsEmpty(dealer) Then 
'Checking when the column which is beincompared with is not empty
           If Not (Application.WorksheetFunction.IsNA(Application.WorksheetFunction.VLookup(dealer, RSC.Sheets("OSB").Range("A2:G1000"), 2, False))) Then
             DealerNumber = Application.WorksheetFunction.VLookup(dealer, RSC.Sheets("OSB").Range("A2:G1000"), 2, False)
             DealerNumber = 0
           End If
          DealerNumber = 0
        End If
        Balance.Sheets("Líquidas").Range("AH" & f).Value = DealerNumber
Next f

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Panagiotis ToumpaniarisSystem EngineerCommented:
you should insert a check like :

if Activecell.Mergecells Then Next f

Open in new window

or something along this line.
Before assigning values to dealer.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ABINAYA MOHANAuthor Commented:
Thank you! Added the below check

If Garantias.Sheets("Garantia Líquidas").Range("C" & f).MergeCells = False Then
        dealer = Garantias.Sheets("Garantia Líquidas").Range("C" & f).Value

Open in new window

It Works!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.