Type mismatch on do until formula

ruzanovsky

New Member
Joined
Jul 12, 2018
Messages
6
Hello,

The code below gives Type Mismatch 13 error:

Code:
Range("F1").Select    Do Until Selection.Value = Sheets("Cortes Proporcionais").Range("L4").Value
        Selection.End(xlToRight).Select

Basically I want the code to press right until it hits the cell equal to Sheets("Cortes Proporcionais").Range("L4").Value

F1 is a blank cell,
G1:M1 are merged cells with the formula =UPPER(TEXT(TODAY();"MMMM"))
N1:T1 are merged cells with the formula =UPPER(TEXT(EDATE(TODAY();1);"MMMM"))
U1:Z1 are merged cells with the formula =UPPER(TEXT(EDATE(TODAY();2);"MMMM")) and
AA1:AF1 are merged cells with the formula =UPPER(TEXT(EDATE(TODAY();3);"MMMM"))

Sheets("Cortes Proporcionais").Range("L4").Value is equal to the month to be used "March", "April", "May" or "June"

Why is the VBA giving type mismatch error? Both cells are string types. I assume it is due to the merged cells?
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Do NOT use merged cells!!! They are the devil, and cause all sorts of problems, especially with VBA!
The good news is that you can get the same visual effect without all the issue caused by them by using the "Center Across Selection" formatting option instead.
I suggest making that change and trying again.
See here for details: https://www.atlaspm.com/toms-tutori...er-across-selection-instead-of-merging-cells/
 
Upvote 0
Try this

Code:
    Range("G1").Select
    Do Until Selection.Cells(1, 1).Value = Sheets("Cortes Proporcionais").Range("L4").Value 
        Selection.End(xlToRight).Select
    Loop

But if the evaluator of the cells is never equal to L4 then the loop enters an endless cycle

Then:

Code:
    Range("g1").Select
    Do Until Selection.Cells(1, 1).Value = Sheets("Cortes Proporcionais").Range("L4").Value Or Selection.Cells(1, 1).Value = ""
        Selection.End(xlToRight).Select
    Loop

Or this:

Code:
    Dim i As Long
    For i = Columns("G").Column To Cells(1, Columns.Count).End(xlToLeft).Column
        Cells(1, i).Select
        If Cells(1, i).Value = Sheets("Cortes Proporcionais").Range("L4").Value Then Exit For
    Next

Why do you want to select the cell, do you want the data or only know the column where the match is found?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,217,438
Messages
6,136,618
Members
450,022
Latest member
Joel1122331

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