type mismatch error 13

whcmelvin

Board Regular
Joined
Jul 27, 2011
Messages
82
I am facing this error when i run this code. the values in SelectRangeAuto is all 0. all are empty cells. the error is caused by AllUnrealizedPandL = WorksheetFunction.Sum(SelectRangeAuto). Please help. Thanks

Code:
Dim SelectRangeAuto As Variant
Dim AllUnrealizedPandL As Double

    With Sheets(EmailSheetAuto)
        SelectRangeAuto = .Range(.Range("J2"), .Range("J2").End(xlDown))
        If .Range("J2").Value <> "" Then
            AllUnrealizedPandL = WorksheetFunction.Sum(SelectRangeAuto)
        End If
    End With
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try this:
Code:
Set SelectedRangeAuto = .Range(.Range("J2"), .Range("J2").End(xlDown))
You might also want to check you are trying to sum the correct range, using xlDown isn't always the best way to find the last row of data.
 
Upvote 0
Hi, the code is suppose to be refreshing every sec. Then when i first use the excel, the range should be empty. while i am using, it will then have values inside. i am thinking that it might be the empty cells that causes the problem but i do not know how to solve it
 
Upvote 0
I used what I suggested on a blank sheet and there was no error.

I think the error is because you are trying to sum an array with over 1 million items, which is a result of using xlDown.

eg if there's nothing below J2 then xlDown will return the very last row in the worksheet

Is there definitely nothing in cell J2 when you get the error?
 
Upvote 0
Ya. there is nothing in J2. hmmm. Btw, does you all know if excel could insert those java charts that in in the internet?
 
Upvote 0
If there's nothing in J2 then your code should skip the Count part.

Try what I suggested or changing to use xlUp and finding the last row from the bottom upwards.

Java Charts? What to do you mean?
 
Upvote 0
Okay thanks. Internet has those financial charts. it uses JAVA. is there any way to import it to the excel?
 
Upvote 0
I've honestly no idea what you mean.:)

Can you post a link to one of these 'java' charts?
 
Upvote 0
That isn't a 'java' chart as far as I can see.

It's something created in Flash.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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