Aure
03-24-2022, 09:03 AM
Hello everyone,
I start by saying that I have clear in my mind what I want to achieve, but I have a very limited knowledge of VBA and therefore cannot write a working code.
What I need is a macro able to operate on an Excel file with 3 sheets ("Selection", "Dataset", and "Output") and follow these steps:
0. The user can place the X where he needs in the "Selection" sheet, then press a button to activate the macro.
1. Check if cell C3 of sheet "Selection" has been marked with a X.
2. If not, start the macro again, but for the following row (so in cell C4).
3. If yes, memorize the first 2 characters of cell A3 (in this example, "A1")
4. Go to sheet "Dataset"
5. Select all rows with code starting with the momorized characters (in this example, "A1")
6. Copy the rows
7. Go to sheet "Output"
8. Paste the rows underneath the title
9. Go to sheet "Selection"
10. Start the macro again for the following row
This is needed so that the user can just select a few categories and instantly produce a report with all the sub-category rows.
In a previous experiment I wrote some simple macros for each category, but that's quite inefficient and also I would need to always specify the row numbers in advance.
Sub Macro_Test()
Sheets("Dataset").Select
Rows("2:11").Select
Selection.Copy
Sheets("Output").Select
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub
I think the steps I planned are a smarter way to approach the problem, but I am not able to write code that complicated :(
Can anyone give me some suggestions/help?
Thanks in advance!
I start by saying that I have clear in my mind what I want to achieve, but I have a very limited knowledge of VBA and therefore cannot write a working code.
What I need is a macro able to operate on an Excel file with 3 sheets ("Selection", "Dataset", and "Output") and follow these steps:
0. The user can place the X where he needs in the "Selection" sheet, then press a button to activate the macro.
1. Check if cell C3 of sheet "Selection" has been marked with a X.
2. If not, start the macro again, but for the following row (so in cell C4).
3. If yes, memorize the first 2 characters of cell A3 (in this example, "A1")
4. Go to sheet "Dataset"
5. Select all rows with code starting with the momorized characters (in this example, "A1")
6. Copy the rows
7. Go to sheet "Output"
8. Paste the rows underneath the title
9. Go to sheet "Selection"
10. Start the macro again for the following row
This is needed so that the user can just select a few categories and instantly produce a report with all the sub-category rows.
In a previous experiment I wrote some simple macros for each category, but that's quite inefficient and also I would need to always specify the row numbers in advance.
Sub Macro_Test()
Sheets("Dataset").Select
Rows("2:11").Select
Selection.Copy
Sheets("Output").Select
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub
I think the steps I planned are a smarter way to approach the problem, but I am not able to write code that complicated :(
Can anyone give me some suggestions/help?
Thanks in advance!