A suggestion. Explain the lines of code when you solve someone's problem.

emmett518

New Member
Joined
Feb 18, 2016
Messages
9
Just wanted to throw out an idea for everyone.

I've read countless posts here where someone asks for a solution to an Excel problem, and one of the experts here writes the code, and posts it online. The experts here obviously know their stuff.

Would it be possible for the person posting the code to provide an accompanying explanation for how it works? I'd like to read a synopsis of what how you decided to solve the problem, and then what each line of code accomplishes, and what each piece of the line specifies.

I know this would take more time, and aggravation, but it would help the rest of us to learn more about VBA, and it would allow someone to figure out how to solve their own problems without having to continually ask for code to be written. Kind of like the giving a fish vs teaching a man to fish thing.

For example, someone posted this code to solve a selecting cells, and moving them. I'd like to see this kind of answer.

___________________________________________

This script finds the number of rows of data in the spreadsheet, goes through this number of rows, and copies the entirety of the row to a second spreadsheet worksheet if there is a value in column G in that particular row.


Sub Create_Scaled_Recipe()

Application.ScreenUpdating = False

Dim lr As Long
Dim cell As Range
lr = Range("A" & Rows.Count).End(xlUp).Row

Sheet2.UsedRange.Offset(1).ClearContents

For Each cell In Range("G4:G" & lr)
If cell <> "" Then
cell.EntireRow.Copy Sheet2.Range("A" & Rows.Count).End(3)(2)
End If
Next

Application.CutCopyMode = False
Application.ScreenUpdating = True
Sheet2.Select

End Sub

Explanation:

Sub Create_Scaled_Recipe() - Label the macro that we're writing, so that it shows up as the title "Scaled_Recipe" when you hit Alt F8 to select a macro.
Application.ScreenUpdating = False -
The macro is going to be looking at each value in column G in each row, and if there's a value there, copy the entire row to the second sheet in the spreadsheet. This command prevents the changes to the spreadsheet from showing up in real time until the macro completes, which would slow down the macro.

Dim lr As Long -
Dimension the variable "lr" to hold the value of numbers
Dim cell As Range -
Dimension the variable "cell" to hold a range of cell addresses (A1, A2:B6, etc)

_____________________________________________________________

Why bother? First, the people who write the online Excel language references don't do a very good job of explaining the commands. Second, you have to know what part of the command is unique to your spreadsheet, and as a result, can't be used to google search the command.

Third, you have to try to decode what the person is trying to do, and why he or she included this line in the solution.

Having an explanation with the code would go a long way toward helping people out.

Thanks
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Just my opinion but....

Have you tried just asking for an explanation? believe it or not everyone who posts a question doesn't always want an explanation.

As you stated this would take more time, and aggravation (actually it normally takes longer than writing the code itself).

If you are not the original poster there is nothing stopping you starting a new thread and asking for an explanation of any code you don't understand.

In general most posters who answer questions are more than willing to answer specific questions about code they post but I doubt there will a great rush to write

a synopsis of what how you decided to solve the problem, and then what each line of code accomplishes, and what each piece of the line specifies.

for every code they post (after all they are not writing a text book they are providing answers on a help forum).

BTW. this probably should have been posted in the lounge.

Link to Lounge v.2.0
 
Last edited:
Upvote 0
Just to follow up on MARK858's comment... you will learn a tremendous amount more about coding and function interaction by trying to decipher the code on your own. And if there is a section of code you cannot figure out, then ask about that piece of code. As Mark said, it always takes a lot longer to explain the code than it takes to write it, so the expedient thing, given we want to help as many people as possible within the time limits imposed on our volunteering efforts, is to post the code and then move on to the next question.
 
Upvote 0
Hi,

Also, it's not necessarily true that the person asking for coding help needs an explanation, it may just be that the poster knows coding but is stuck at a certain point and needs a little help.
For the Helper to automatically write an explanation of the code might just be a waste of effort and time.
 
Upvote 0
AND
everyone here is a volunteer, giving their time and effort freely.
IF the person writing the code has to provide line by line explanations, they'll probably reconsider posting.
Most posters, as mentioned in the other posts, will ask for specific explanations, if they need them....and the person writing the code will either give an explanation, or refer the OP to a source where they can gain more knowledge in their own time.

Keep in mind also that if you place the cursor over a portion of code and Press F1, it will refer you to the appropriate section in the Help menu.
 
Upvote 0

Forum statistics

Threads
1,215,506
Messages
6,125,189
Members
449,213
Latest member
Kirbito

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