Type Mismatch Error

ss6857

New Member
Joined
Jan 17, 2011
Messages
27
I have some code and I thought it was pretty basic code but it's giving me a type mismatch error on the very last line. Any suggestions?

Code:
Sub Email()
    Dim LR As Long
    Dim ws As Worksheet
    Dim vFilePath As String
    Dim CurrentFile As String
    
    Dim OutApp As Object
    Dim OutMail As Object
    Dim EmailTo As String
    Dim EmailCC As String
    Dim EmailSub As String
    Dim EmailBody As String
    
    vFilePath = Range("rFilePath").Value
        
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Master" And ws.Name <> "Check" And ws.Name <> "Data" And ws.Name <> "Template" _
        And ws.Name <> "Library" And ws.Name <> "Total EQL Scorecard" And ws.Name <> "EQL Com Scorecard" _
        And ws.Name <> "Control" Then
        
        CurrentFile = vFilePath & ws.Range("A7") & ".xlsx"
            ws.Copy
            ThisWorkbook.Sheets("Master").Copy after:=ActiveSheet
            ActiveWorkbook.SaveAs Filename:=CurrentFile, _
            FileFormat:=xlOpenXMLWorkbook
            
 ThisWorkbook.Activate
 
 For LR = ThisWorkbook.Sheets("Library").Range("B2").End(xlUp) To 2 Step -1
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
May we know what line gives the error?

EDIT:

Code:
For LR = ThisWorkbook.Sheets("Library").Range("B2").End(xlUp)[COLOR=red].Row[/COLOR] To 2 Step -1
However, you can't go very far up from row 2, so probably
Code:
For LR = ThisWorkbook.Sheets("Library").[COLOR=red]Cells(Rows.Count, "B").End(xlUp).Row[/COLOR] To 2 Step -1
 
Last edited:
Upvote 0
Yeah the last line.

Code:
For LR = ThisWorkbook.Sheets("Library").Range("B2").End(xlUp) To 2 Step -1
 
Upvote 0
Try adding Row.

Oh, and it might be an idea to start in the last row not the 2nd row.
Code:
For I = ThisWorkbook.Sheets("Library").Range("B" & Rows.Count).End(xlUp).Row To 2 Step -1
 
Upvote 0
Thank you. It atleast allows it to happen now, haha. i made it (xlDown) instead up (xlUp).

Does this bring back the number of rows? Such as, there are 25 rows. or does it goes through each row one at a time?
 
Upvote 0
xlDown is equivalent to selecting the cell and doing Ctrl+Down
 
Upvote 0
You need to be careful in using xlDown/xlUp.

If you use xlDown you could find yourself looping through every row, regardless of whether or not they have data.
 
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