Excel VBA Loop - Error Type mismatch

countryfan_nt

Well-known Member
Joined
May 19, 2004
Messages
758
Hello friends! Hope all is well!

The below code (first one) is giving me an error (Type Mismatch).

I am basically running a loop; where the code goes from C4:C whatever); and the code will stop when the cells in C are empty (i.e. equals “”).
Please kindly help me and thanks a lot in advance!


Code:
Sub pdfit()
    
    Do Until ActiveCell.Value = ""
        
    Sheets("EnterID").Select
    Range("C3").Select
        ActiveCell.Value = ActiveCell.Value
        ActiveCell.Offset(1, 0).Select
    
        Selection.Copy
    
    
    Sheets("Results").Select
    Range("D2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

Application.CalculateFull

Call Picture5_Click

    Loop
End Sub


Code:
Sub Picture5_Click()
Dim LoginName As String
Dim Name As String

LoginName = UCase(GetUserID)
Name = Sheets("Results").Range("AA14")

' Assemble the filename
     sFileName = "C:\Users\" & LoginName & "\Desktop\" & Name & ".pdf"
 
' Save the File as PDF
    
    Sheets("Results").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        sFileName, Quality _
        :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        OpenAfterPublish:=False

End Sub
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I am not getting a type mismatch when running your first code without calling your second sub (btw, you haven't stated which line you get the error on) and I am not going to try it with the second code because I have no idea of your setup.

Having said that, I also can't tell exactly what you are trying to do with the first sub as you don't describe it but my best interpretation at the moment is below.

Is it close?
Does it error as is?
If it doesn't, does it error once you uncomment the Call Picture5_Click code line?

Rich (BB code):
Sub pdfit12()

    Dim c As Range
    
    With Sheets("EnterID")
        .Range("C3").Value = .Range("C3").Value

        For Each c In .Range("C4:C" & .Range("C" & Rows.Count).End(xlUp).Row)
            Sheets("Results").Range("D2").Value = c.Value
            Application.CalculateFull

            'Call Picture5_Click
        Next
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,044
Members
448,543
Latest member
MartinLarkin

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