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
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