type mismatch macro excel

tuytuy

Board Regular
Joined
Mar 28, 2013
Messages
75
Code:
'copy COST OF BLACKBERRY DATA NATIONAL


ActiveWorkbook.Sheets("Section_14").Activate
If Range("K:K") = "Blackberry Roaming" Then
sumbbmint = WorksheetFunction.Sum(Range("P$3:P$1048576"))
ActiveWorkbook.Sheets("SynthesisVSD").Activate
Range("A26").Value = "Cost of BlackBerry National data consumption:"
Range("B26").Value = sumbbmint
End If

Hi i was trying to run this little code in vba, but i get an error 14 type mismatch on the If Range("K:K") = "Blackberry Roaming" Then" line, i have no idea why ?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Range("K:K") is a column of cells. You cannot compare a column of cells to a text string like that. I cannot determine your intent from your code. So I can't recommend a solution.
 
Upvote 0
Problem solved i used this instead
Code:
'copy COST OF BLACKBERRY DATA NATIONAL


ActiveWorkbook.Sheets("Section_14").Activate
sumbbmn = WorksheetFunction.SumIf(Range("K$3:K$1048576"), "BlackBerry usage", Range("P$3:P$1048576"))
ActiveWorkbook.Sheets("SynthesisVSD").Activate
Range("A26").Value = "Cost of BlackBerry National data consumption:"
Range("B26").Value = sumbbmn
 
Upvote 0
You wouldn't have to Activate a worksheet to reference the cells on it. The code below does the same thing.
Code:
[COLOR=green]'copy COST OF BLACKBERRY DATA NATIONAL[/COLOR]
Sheets("SynthesisVSD").Range("A26").Value = "Cost of BlackBerry National data consumption:"
[COLOR=darkblue]With[/COLOR] Sheets("Section_14")
    Sheets("SynthesisVSD").Range("B26").Value = WorksheetFunction.SumIf(.Range("K:K"), "BlackBerry usage", .Range("P:P"))
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,214,575
Messages
6,120,334
Members
448,956
Latest member
Adamsxl

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