'Comments In Code

DocAElstein

Banned user
Joined
May 24, 2014
Messages
1,336
'Comments In Code

Hi,
. As a beginner I find it useful to write lots of comments (Those written in 'green) in code. Although we all know that this is good practice, this could be a bit confusing sometimes, for example when a profi looks through the codes I post in Threads. I would like to keep the comments in my codes, but do not want to annoy readers of my code!! (at least any more than usual!!). Is there a quick way to remove the comments.. For example is there an option or way to do this in the Mr Excel HTML Code Maker.
. It is no big Deal, I just thought I would ask in passing.
Thanks,
Alan
Bavaria
 
'Comments In Code

Hi,
. As a beginner I find it useful to write lots of comments (Those written in 'green) in code. Although we all know that this is good practice, this could be a bit confusing sometimes, for example when a profi looks through the codes I post in Threads. I would like to keep the comments in my codes, but do not want to annoy readers of my code!! (at least any more than usual!!). Is there a quick way to remove the comments.. For example is there an option or way to do this in the Mr Excel HTML Code Maker.
. It is no big Deal, I just thought I would ask in passing.
Thanks,
Alan
Bavaria

Hey DocAElstein,

I am not sure about the Mr Excel HTML Code Maker, but what I always do is make a specific comment block of symbols so I can just Find and remove it. Always back up your code before attempting this. For example the standard comment symbol is '. I use '#@. I type CTRL+F and then type in my specific text block to find and replace it with a blank space. It doesn't remove the blank lines between the code, but will remove the comments. The go into the edit tab and undo the removal of the comments. Test it first to see if it works on some sample code. Always back up your code befoe attempting this!

later

Ty
 
Hi Tyron,
. Thanks for the Reply. I am not quite sure I understand what you are doing. Are you saying for blank lines you use ' and for comments '#@ ? And then you use the search function (Ctrl F) to find your comments quickly ?.
. That sounds like you have a large program with few comments and so your method helps to quickly locate your comments ?
. I tend to have small or medium size codes with lots of comments. So finding the comments is no problem. (They are everywhere!!!! – see for example my last thread! - http://www.mrexcel.com/forum/excel-questions/795477-interior-color-rgb-values.html) I was just looking for a way to delete all the comments at once rather than tediously going from line to line and deleting each comment.
Thanks again for the reply
Alan
Bavaria
 
Hi Tyron,
. Thanks for the Reply. I am not quite sure I understand what you are doing. Are you saying for blank lines you use ' and for comments '#@ ? And then you use the search function (Ctrl F) to find your comments quickly ?.
. That sounds like you have a large program with few comments and so your method helps to quickly locate your comments ?
. I tend to have small or medium size codes with lots of comments. So finding the comments is no problem. (They are everywhere!!!! – see for example my last thread! - http://www.mrexcel.com/forum/excel-questions/795477-interior-color-rgb-values.html) I was just looking for a way to delete all the comments at once rather than tediously going from line to line and deleting each comment.
Thanks again for the reply
Alan
Bavaria

Hey DocAElstein,

Nope. Actually when I code I have comments for each step of the process so that I can cut snippets for other code later if possible.

I don't have any blank lines. Only code and comments. You are right in that I put a special comment text block before each comment. This allows me to delete all comments at one time using the "replace all" option when using the Find/Replace. I was just refering to the fact that the find/replace replaces all of my comments with blank lines. I am still working on getting rid of the blank lines. Maybe in the near future I will write a piece of VBA (when I become more proficient) to remove comments.

What happens is once my comment text block has been replaced with a space the text then turns red which shows me what lines need to be deleted. I understand that it isn't automatic, but it does allow me to select enough to make it go fast.

later

Ty
 
Hi Tyron,

. Thanks again.
. If I understand correctly then your method for me means my comments turn red instead of green? And then in your method I could just you could just as well use ' instead of '#@ and use ' as the search criteria ?
. Sorry if I have missed the point. I do not quite see the advantage of using '#@ Insted of ' in my case. Are you saying that You use ' For comments directly after code, and '#@ for lines with just code?
. Do you have a snippet of any of your codes you could send. Maybe I can see better then what you mean. I am a complete beginner (or rather late starter!) so maybe I missed something obvious in what you have been saying.
Alan
 
Hi Tyron,

. Thanks again.
. If I understand correctly then your method for me means my comments turn red instead of green? And then in your method I could just you could just as well use ' instead of '#@ and use ' as the search criteria ?
. Sorry if I have missed the point. I do not quite see the advantage of using '#@ Insted of ' in my case. Are you saying that You use ' For comments directly after code, and '#@ for lines with just code?
. Do you have a snippet of any of your codes you could send. Maybe I can see better then what you mean. I am a complete beginner (or rather late starter!) so maybe I missed something obvious in what you have been saying.
Alan

Hey DocAElstein,

Here is a snippet of one code line:

Code:
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
'#@ This is a comment *
Dim rCell As Range

I can see your point. However I find the red easier to find and less strain on my eyes then the green. I too would be called a late starter. For the VBA part of Excel anyways. I have been using plain excel spreadsheets for 10 years now.

If you notice I also put an "*" asterisk at the end of my comments. I keep hoping that Microsoft will implement a way to search for a starting character and ending character so that I can find whole lines rather then be limited to one word searches.

That is why I was saying that I may look for a way to write some VBA that can do it in the future. Other than that I am not sure if there is a way to accomplish what we would like to do. If you find a way please let me know or update this thread.

later

Ty
 
To whack all comments, do Find & Replace, tick Use Pattern Matching, and replace '* with nothing.
 
To whack all comments, do Find & Replace, tick Use Pattern Matching, and replace '* with nothing.

Hey shg,

Thanks for the solution. Works like a charm. Now I won't have to worry about manual deletion anymore.

later

Ty
 
You're welcome.
 

Forum statistics

Threads
1,223,868
Messages
6,175,082
Members
452,611
Latest member
bls2024

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