logo
vbRad Home
Source Code
Book Reviews
Forum
Links
About Us
Contribute

Compare Databases with SQL Effects Clarity
 
 How to quickly (really quickly) comment out blocks of code

Posted on
2/18/2001
Author:
Robert Gelb
Email:
Not Shown
Applies To OS:
All
Product:
5, 6



From the files of Stupid Keyboard Tricks

Since version 1.0 VB lacked a block comment feature that C/C++ programmers love so dearly.  Finally in version 5, the mothership provided us with half of the solution - one could now go to the Customize menu and add the Comment Block and Uncomment Block button to the toolbar or the menu.  And that was good.  But if you are a keyboard jockey like us, you want something faster and preferably something faster than the /*...*/ operator in C/C++.  This is the story of how to do it:

  1. Right click on the toolbar and select Customize... menu
  2. Under Categories click on Edit, then select Comment Block in the Commands listbox.
  3. Now drag the Comment Block entry onto the Menu Bar (yep! the menu bar)
  4. You should now see a new icon on the menu bar. 
  5. Make sure that the new icon is highlighted (it will have a black square around it) and click Modify Selection button on the Customize dialog box.
  6. An interesting menu will popup.  Under name, add an ampersand to the beginning of the entry.  So now instead of Comment Block it should read &Comment Block.  Press Enter to record the change.
  7. Click on the Modify Selection button once again and select Image and Text.
  8. Dismiss the Customize dialog box.
  9. Now highlight any block of code and press Alt-C.  Voila.
  10. Do the same thing for the Uncomment Block or any other commands that you find yourself using often.

ToolbarEditor With Commented Out Block

 


Add Your Comment  

Name: Email Address: all fields optional
Notify me via email when someone responds to this message (valid email required).

Enter the word:
 



Comments
#1. By Anonymous. Posted on 3/7/2006 10:41:02 AM
this is stupid

#2. By Anonymous. Posted on 3/8/2006 7:54:35 AM
Reply to #1. Stupid or not, it gets the job done. I've been using this since VB6, into VS.NET 2002, 2003 and 2005. There isn't a faster way to uncomment stuff.

#3. By Anonymous. Posted on 5/12/2006 5:23:23 PM
Wonder who the Hack is that said this is stupid?? Obviously someone too stupid to know better. Works great thanks for the tip.

#4. By Anonymous. Posted on 7/4/2006 5:26:45 AM
it helps. it's better than nothing.

#5. By ghh3rd. Posted on 8/9/2006 10:15:17 PM
Glad I stumbled onto this. I found that there's already a button on the Excel VBA toolbar to do this that I wasn't aware of. No more waking up my co-workers with my repetitive clicking while I'm commenting or uncommenting many rows of code.

Granville

#6. By Mimo. Posted on 11/23/2006 1:40:08 AM
a real jockey u r
many thanks 4 u

#7. By Anonymous. Posted on 12/15/2006 6:50:51 AM
Thanks a lot, this really helps when it comes to testing different methods of code :D

#8. By Anonymous. Posted on 1/5/2007 6:02:45 AM
Nice tip, not just for comment/uncomment but also for customizing shortcuts to other actions. Thanks!

#9. By Peter. Posted on 2/2/2007 5:54:35 PM
Oh, yes!!!

This was the most useful thing I've read all day. I've been in per-line commenting hell for months. The tip on customization and the keyboard shortcut are both just as awesome too. Thanks so much!

#10. By world. Posted on 3/18/2007 2:16:53 AM
hello world http://bcreditused.info http://carloanp.info http://refincarloan.info http://badcredith0melan.info http://creditcard0ffer.info

#11. By Chris. Posted on 6/20/2007 6:30:56 PM
This is great!! I didn't even know that Excel had this feature... I was used to C# easy context-menu comment/uncomment... happy to find this back in Excel! This is a real time saver!

#12. By John. Posted on 9/19/2007 6:48:07 PM
somestrangetextvista

#13. By Anonymous. Posted on 9/26/2007 4:26:22 PM
Quote:
#1. By Anonymous. Posted on 3/7/2006 10:41:02 AM
this is stupid
________________________________________________

You're stupid, you probably have no idea what is discussed here...

Robert, GREAT TIP ! Thanks a bunch, really helps!

#14. By Anonymous. Posted on 11/13/2007 9:40:30 AM
There is another to do it:
- insert before the first line to be changed to comment
#If false Then
- insert after the last line to be changed to comment
#End If

#15. By ghh3rd. Posted on 11/13/2007 9:57:55 PM
Hey anonymous...

Thanks for the additional tip to use:

#If false Then
- insert after the last line to be changed to comment
#End If

It works great!

GHH

#16. By g_p_k_. Posted on 12/17/2007 7:46:09 AM
For this tip, I truly love you...

#17. By Anonymous. Posted on 2/19/2008 10:32:45 PM
',down,left,',down,left,',down,left,',down,left,',down,left,',down,left,',down,left,',down,left,',down,left,',down,left,',down,left, MAN I WISH I KNEW THIS SOONER HAHAHA

Thanks so much

#18. By Anonymous. Posted on 7/4/2008 11:42:56 AM
fantastic! sped up my copious debugging of the rubbish code I generate no end.

#19. By Anonymous. Posted on 2/4/2009 1:43:42 AM
A: first method is 100% rubbish, too much messing around to obtain simplest result imaginable, I'm sure you're a big fan of Bill Gates too ... ROFL

B: second method better, but still not highlighted in crappy .NET
#If false Then
#End If

C: /* ... */ = ultimate answer leading to conclusion: you people need to start using proper coding languages :D

Question: Why use VB ???

#20. By Anonymous. Posted on 2/4/2009 9:18:34 AM
A: first method is 100% rubbish, too much messing around to obtain simplest result imaginable, I'm sure you're a big fan of Bill Gates too ... ROFL

B: second method better, but still not highlighted in crappy .NET
#If false Then
#End If

C: /* ... */ = ultimate answer leading to conclusion: you people need to start using proper coding languages :D

Question: Why use VB ???

#21. By Anonymous. Posted on 2/4/2009 9:18:47 AM
A: first method is 100% rubbish, too much messing around to obtain simplest result imaginable, I'm sure you're a big fan of Bill Gates too ... ROFL

B: second method better, but still not highlighted in crappy .NET
#If false Then
#End If

C: /* ... */ = ultimate answer leading to conclusion: you people need to start using proper coding languages :D

Question: Why use VB ???

#22. By Anonymous. Posted on 6/10/2009 11:01:48 AM
Typical Microsoft.... bandaid in a feature a few years too late.
how about '/ COMMENT BLOCK /' as something more practical
(at least they made an effort i suppose).

#23. By RealAnon. Posted on 8/14/2009 8:31:55 AM
To the two tools above me: /**/ comment blocks run into issues when you already have a comment block inside. So no system is perfect. Personally, I like setting a key command to comment and uncomment a section of code.

VB is useful when you need to use excel (which if you don't know the uses for, I don't think I could explain it) and/or when you need something done quickly. I love my C++ when I want something exactly how I want it or need something really fast many times. But lets face it, if I want to do some quick accounting or records keeping, vb (and vba) is like writing it out in english and only takes a few minutes, can be shared and edited by many, and takes advantages of all of excel and accesses' features.

Lurk more, troll less. VB has it's place. Assuming you're smarter than everyone does not.
~Dill

#24. By RealAnon. Posted on 8/14/2009 9:12:43 AM
To the two tools above me: /**/ comment blocks run into issues when you already have a comment block inside. So no system is perfect. Personally, I like setting a key command to comment and uncomment a section of code.

VB is useful when you need to use excel (which if you don't know the uses for, I don't think I could explain it) and/or when you need something done quickly. I love my C++ when I want something exactly how I want it or need something really fast many times. But lets face it, if I want to do some quick accounting or records keeping, vb (and vba) is like writing it out in english and only takes a few minutes, can be shared and edited by many, and takes advantages of all of excel and accesses' features.

Lurk more, troll less. VB has it's place. Assuming you're smarter than everyone does not.
~Dill

#25. By RealAnon. Posted on 8/14/2009 5:18:33 PM
To the two tools above me: /**/ comment blocks run into issues when you already have a comment block inside. So no system is perfect. Personally, I like setting a key command to comment and uncomment a section of code.

VB is useful when you need to use excel (which if you don't know the uses for, I don't think I could explain it) and/or when you need something done quickly. I love my C++ when I want something exactly how I want it or need something really fast many times. But lets face it, if I want to do some quick accounting or records keeping, vb (and vba) is like writing it out in english and only takes a few minutes, can be shared and edited by many, and takes advantages of all of excel and accesses' features.

Lurk more, troll less. VB has it's place. Assuming you're smarter than everyone does not.
~Dill

#26. By Kydja. Posted on 8/16/2009 7:39:40 PM
I love u people, do u now that?
Two ways to comment in one minute!!!
I am a better man now!!!!!!!

"Then came a man before His feet he fell
Unclean said the leper and rang his bell
Felt the palm of a hand touch his head
Go now go now you're a new man instead
All going down to see the Lord Jesus
All going down to see the Lord Jesus
All going down"

| |
| HURAAY!!!! |
| |
- -< ---I
8-)- <
- -< ---l

#27. By Teixeira. Posted on 8/28/2009 4:26:32 PM
Great, great!

Most useful thing, great step by step. The tip on customization and the keyboard shortcut are super. Thanks so much!

#28. By Amateur_programmer. Posted on 9/17/2009 8:49:00 PM
thanks so much this just made my life easier!!!
~Florida~

#29. By DJ. Posted on 10/9/2009 1:01:33 AM
I loved this tip. 10 years using VB and I didn't know this.

#30. By Anonymous. Posted on 10/19/2009 6:18:13 AM
thanks bro.....
nice tips~

#31. By Anonymous. Posted on 4/23/2010 10:55:22 AM
Thanks alot mate - truly useful!!

#32. By Anonymous. Posted on 4/23/2010 10:55:27 AM
Thanks alot mate - truly useful!!

#33. By Wylie. Posted on 7/23/2010 12:23:44 AM
Dude, super cool! Thanks for sharing.

#34. By Wylie. Posted on 7/23/2010 12:39:29 AM
Dude, super cool! Thanks for sharing.

#35. By Josh. Posted on 8/12/2010 10:46:06 AM
Amazing! So simple, yet so powerful! This will probably go a long way towards reducing my risk of RSI. Definitely in my top 10 most useful VB tips of all time!

#36. By Josh. Posted on 8/12/2010 4:04:46 PM
Amazing! So simple, yet so powerful! This will probably go a long way towards reducing my risk of RSI. Definitely in my top 10 most useful VB tips of all time!

#37. By Anonymous. Posted on 8/28/2010 1:25:30 PM
thanks for the tip :)
the first commentor is a jerk

#38. By mimB. Posted on 9/8/2010 7:13:04 PM
Excellent!
Thank you so much for posting this!

#39. By xtian. Posted on 10/10/2010 7:10:25 PM
thanks, this helped me saves time when debugging and wanted to skip blocks of codes....

#40. By Alex. Posted on 10/27/2010 9:59:03 AM
I am back doing some Excel VBA for the first time in years and had forgotten there aren't shortcut keys for commenting and uncommenting blocks; I kept trying CTRL-K-B etc.

This is the best solution I have seen. Thanks!

#41. By Anonymous. Posted on 11/12/2010 1:48:28 AM
There is also the uncomment block button (The one with the arrow)

#42. By Anonymous. Posted on 11/12/2010 1:48:30 AM
There is also the uncomment block button (The one with the arrow)

#43. By Raul Black. Posted on 12/12/2010 9:51:01 PM
"I kept trying CTRL-K-B etc."

Highlight the code block and then hit CTRL-K + CTRL-C to comment or CTRL-K + CTRL-U to uncomment.

#44. By Anonymous. Posted on 12/19/2010 6:34:41 AM
stupid?
he/she most probably means microsoft...
that there should be a better way to help the programmers.
hahaha
give him/her a break

#45. By Anonymous. Posted on 4/11/2011 9:11:55 AM
Great trick ! Thanks

#46. By Anonymous. Posted on 6/4/2011 8:23:51 AM
brilliant, thanks:)

#47. By JasonK. Posted on 6/5/2011 1:23:18 AM
The [alt][C] shortcut feature does not seem to work for me in Excel 2003.

#48. By Twitter:WontFretBrett. Posted on 6/21/2011 8:09:11 PM
Wow. GENIUS

#49. By Anonymous. Posted on 8/5/2011 6:55:46 AM
This is just what I want! (in VBA)

#50. By Abdus Sami. Posted on 10/12/2011 7:06:57 AM
Beautiful. Takes care of the problem once and for all.

#51. By Anonymous. Posted on 11/7/2011 12:13:34 PM
Thank you

#52. By Jatin Gangajaliya. Posted on 11/15/2011 5:43:43 AM
Thanks.

#53. By Anonymous. Posted on 3/14/2012 6:29:00 PM
Thanks buddy, this's very useful!

#54. By Anonymous. Posted on 7/17/2012 12:15:24 PM
I would just like to reiterate that #1 and #20 By Anonymous are complete morons!

This is a great tip, thanks!

#55. By amit. Posted on 10/8/2012 12:46:10 PM
thanks.......
It works in excel macro.

#56. By Jerry. Posted on 7/30/2013 6:43:38 PM
This is terrific!! I wish I would have know this a couple years ago.

#57. By Anonymous. Posted on 8/29/2013 5:51:08 PM
New Learining !!!!!!!!!!!!!!
Its working fine :)
Thanks

#58. By Martin. Posted on 7/25/2014 3:21:49 AM
Fantastic tip - thank you very very much!