Hi guys.
I am trying to make a nice testing/results file at work.
The idea is that when we get a request, the person responsible for the testing will copy the test list from a separate request file (test marked with X needs to be performed) to a sheet called "info", then they specify how many samples to test and with a button it will update the sheet called "results" to have the correct test shown in the table with the proper sample amount and hide the sheets from tests that don't need to be tested.
I tried do create something of my own, but it's not going as planned.
For the "info" sheet, it looks like this.
Not all tests will need to be added in the table in the "results" sheet (prep work), so my plan was to hide those to make it look a bit neater.
Next, we have the results sheet.
This is just a table with all possible tests.
In a different file, we have a very simple macro which will add rows to the table so it will have the correct amount of samples. When using that code for this one, things seem to break a little. I have to add a blank row below (which I then make 0 pixels tall), otherwise it will create extra rows with wrong numbering. (In the following picture I wanted 5 samples, as you can see this did not happen). I have no clue why this happens (Something to do with the rows below?).
See the code below:
To make sure it will number correctly, Cell"B8", has the following formula: = IF(B7 = "Nr";1;B7 + 1).
Then, there's the whole hiding of columns and sheets part where I tried something by myself. It does work, but if a new test gets added or a current one gets removed, it will break (Cause I am selecting a specific range, which will no longer correspond to that test if columns get added or removed in front of this).
So then my thought went like this: If a test with code "102" is NOT marked with "X" in the "info" sheet, search for "102" in row 3 of the "results" sheet and hide that column and the sheet (if it has any). This works (just need to change the row numbers for the "info" sheet if something changes there), but when it comes to tests that have multiple columns it doesn't work.
Below my code for this.
This one works, cause only 1 column is involved
The next one will only hide the first column, keeping the second one unhidden
Also. some sheets will have multiple tests assigned to them (701 + 702 for example). My guess is to add and "OR" part to the code to make sure it work, right?
Once the table is finished, all visible sheets need to have a table with the correct amount of rows corresponding the samples to be tested. I will make a separate post for that once this is in place and I have given it a go myself
Could someone help me with my problems above and maybe explain it a bit so I can figure it out by myself next time?
If there are any questions, or if something is unclear, please let me know and I can explain it a bit more
Help would be much appreciated!
-Melissa
I am trying to make a nice testing/results file at work.
The idea is that when we get a request, the person responsible for the testing will copy the test list from a separate request file (test marked with X needs to be performed) to a sheet called "info", then they specify how many samples to test and with a button it will update the sheet called "results" to have the correct test shown in the table with the proper sample amount and hide the sheets from tests that don't need to be tested.
I tried do create something of my own, but it's not going as planned.
For the "info" sheet, it looks like this.
Not all tests will need to be added in the table in the "results" sheet (prep work), so my plan was to hide those to make it look a bit neater.
Next, we have the results sheet.
This is just a table with all possible tests.
In a different file, we have a very simple macro which will add rows to the table so it will have the correct amount of samples. When using that code for this one, things seem to break a little. I have to add a blank row below (which I then make 0 pixels tall), otherwise it will create extra rows with wrong numbering. (In the following picture I wanted 5 samples, as you can see this did not happen). I have no clue why this happens (Something to do with the rows below?).
See the code below:
VBA Code:
Dim X, amount, W As Integer
Dim samples As Variant
samples = Worksheets("Info").Range("C2").Value
amount = samples - 1
Application.ScreenUpdating = False
Sheets("results").Select
X = 8
Do Until X = 8 + amount
Rows(X).Select
Selection.Copy
Rows(X + 1).Select
Selection.Insert shift:=xlDown
X = X + 1
Loop
To make sure it will number correctly, Cell"B8", has the following formula: = IF(B7 = "Nr";1;B7 + 1).
Then, there's the whole hiding of columns and sheets part where I tried something by myself. It does work, but if a new test gets added or a current one gets removed, it will break (Cause I am selecting a specific range, which will no longer correspond to that test if columns get added or removed in front of this).
VBA Code:
If Sheets("Info").Range("C23").Value = "" Then
Sheets("203").Visible = False
Sheets("Results").Columns("H:I").Hidden = True
End If
So then my thought went like this: If a test with code "102" is NOT marked with "X" in the "info" sheet, search for "102" in row 3 of the "results" sheet and hide that column and the sheet (if it has any). This works (just need to change the row numbers for the "info" sheet if something changes there), but when it comes to tests that have multiple columns it doesn't work.
Below my code for this.
This one works, cause only 1 column is involved
VBA Code:
If Sheets("Info").Range("C18").Value = "" Then
Sheets("Results").Select
For W = 1 To 100
If Cells(3, W).Value = "102" Then
Columns(W).Hidden = True
End If
Next W
End If
The next one will only hide the first column, keeping the second one unhidden
VBA Code:
If Sheets("Info").Range("C22").Value = "" Then
Sheets("Results").Select
For Each W In Range("C3:CM3").Cells
If W.Value = "202" Then
W.EntireColumn.Hidden = True
Sheets("202").Visible = False
End If
Next W
End If
Also. some sheets will have multiple tests assigned to them (701 + 702 for example). My guess is to add and "OR" part to the code to make sure it work, right?
Once the table is finished, all visible sheets need to have a table with the correct amount of rows corresponding the samples to be tested. I will make a separate post for that once this is in place and I have given it a go myself
Could someone help me with my problems above and maybe explain it a bit so I can figure it out by myself next time?
If there are any questions, or if something is unclear, please let me know and I can explain it a bit more
Help would be much appreciated!
-Melissa