So simple but it just doesn't work!

Peterfallen

New Member
Joined
Jun 16, 2015
Messages
11
I'm new to Macros and working with a training tutorial, and there's a really simple problem, I just cannot figure out. I feel so stupid asking but i need help.

Here's my code.

So... I copied and pasted the line currently ' - which works fine
But when I type the line, I get an "Unable to get SpecialCells property of the Range class" error.

Please help me.



Sub get_blanks()


Selection.CurrentRegion.Select


Selection.SpecialCells(x1CellTypeBlanks).Select
'Selection.SpecialCells(xlCellTypeBlanks).Select




End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi & welcome to MrExcel
Your first line has X1 (number 1) rather than Xl (lower case L)
 
Last edited:
Upvote 0
OMG.... thank you!
By the way, since you are apparently typing the SpecialCells constants long-hand, you can save yourself some typing by omitting "CellType" text within the constant's name. These will both will cause the SpecialCells function to produce the same result...

Selection.SpecialCells(xlCellTypeBlanks).Select

Selection.SpecialCells(xlBlanks).Select

You can also omit the "CellType" text from each of the other possible SpecialCells arguments as well.
 
Last edited:
Upvote 0
Or if being really lazy..

Code:
Selection.SpecialCells(4).Select
 
Upvote 0
Or if being really lazy..

Code:
Selection.SpecialCells(4).Select
Personally, I hate "magic numbers" as they can be hard to remember or figure out 6 months from now when you need to modify the code for some reason.
 
Upvote 0
Hi Rick, personally I don't treat them as "magic numbers" but rather just enumeration, but that is probably because I am so used to using specialcells.

As I stated it is lazy but so is using the bracketed version of evaluate which seems commonplace now (not saying you do this) especially when just referring to a range, I also think the same with resizing to the last row rather than directly referring to the range using last row.

If I am coding for myself I have no problem remembering or figuring out 6 months from now what specialcells(4) or specialcells(12) mean and are doing but it is what you are used to.

I am more concerned that the code doesn't have anything to handle the situation if there are no blank cells.

As with most things to do with VBA (and you have implied) there is a lot down to personal taste and also whether you are teaching someone something they are unfamiliar with.
 
Upvote 0

Forum statistics

Threads
1,214,946
Messages
6,122,401
Members
449,081
Latest member
JAMES KECULAH

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