Finding commas in code

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
693
Office Version
  1. 365
Platform
  1. Windows
I have MANY MANY dim statements in my code and I wrote them like below

Dim a, x, c, f

As I learn code I realize I should write them more like this :

Dim a as string
Dim x as integer ….. and so on.

Is there a vba code that will find the commas in the code, put it on the next line and change it to Dim so?

Dim a, x, c, f will look like:

Dim a
Dim x
Dim c
Dim f

This would make it SO much easier for me to find what kind of variable it is and change it.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
One could write self-modifying code to do that, after registering the VBA Extensibility library and relaxing the Trust Center settings to Trust Access to the project object model. I do not recommend that, though, because you can easily break your project and that trust setting increases your risk from malware. If you learn something about regex, you could use that with a text editor, e.g., Notepad++, on exported code modules or within the VBA editor if you install MZ-Tools.
 
Upvote 0
To just find such lines, you could tick Search Project and Use Pattern Matching in the Find dialog, and search for Dim *,
 
Upvote 0
Thank You both for the reply. Searching out the variables has been hard because I use the same word in other variables. IE: Column, First_Column and Second_Column etc... The FIND function does not give me a way to distinguish between them. I think I will just have to do it manually.

Thanks Again
 
Upvote 0
Thank You both for the reply. Searching out the variables has been hard because I use the same word in other variables. IE: Column, First_Column and Second_Column etc... The FIND function does not give me a way to distinguish between them.
Put a check mark in the "Find Whole Word Only" checkbox on the Find dialog box maybe?
 
Upvote 0
I tried that but it cannot distinguish between column and first_column etc. I have many similar variables with the word column in it.

Thanks
 
Upvote 0
I tried that but it cannot distinguish between column and first_column etc. I have many similar variables with the word column in it.
Hmm, you are absolutely right and I learned something new... the VB editor Replace dialog does not see underline characters as being part of a word. The reason I never noticed this before is that I do not use underlined characters in my variable, function or subroutine names; rather, I prefer to use a form of "camel notation" where I lower case all letters except for the first letter of words or abbreviated words within the variable name. So rather than writing first_column, I would use FirstColumn instead. Using that type of notation, as it turns out, eliminates the problem you are now facing. As to your problem, I think you will need to do what jpvh8 suggested at the end of Message #2 .
 
Upvote 0
Actually I am going to go with your idea and try to change mind to the way you did it.
Thanks
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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