Randomly delete 2 columns in every row within a range

VikingLink

New Member
Joined
Jun 18, 2022
Messages
30
Office Version
  1. 365
Platform
  1. Windows
I'm making an Excel file to help my pupils study their irregular verbs. To help them practise, I want my Excel to have a macro button to randomly clear 2 out of 3 verb forms on every row. Can anyone help me achieve this?

In Range(C6:E114) it has to clear the contents of C6 and D6, or D6 and E6, or C6 and E6. And then the same for every other row within the range, at random.

example.jpg
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
VBA Code:
Sub test()

    Dim i&, r%, ii%

    For i = 6 To Cells(Rows.Count, "B").End(3).Row
        r = WorksheetFunction.RandBetween(3, 5)
        For ii = 3 To 5
            If ii <> r Then
                Cells(i, ii).ClearContents
            End If
        Next ii
    Next i

End Sub
 
Upvote 0
Solution
I would like to expand on this code, by adding the condition that the above VBA only does its thing if column Q equals FALSE. Could anyone possibly help me out? I'm pretty confident in using formulas, but VBA is above my skill level atm.
 
Upvote 0
Try this:
VBA Code:
Sub test()

    Dim i&, r%, ii%

    For i = 6 To Cells(Rows.Count, "B").End(3).Row
        If Cells(1, "Q").Value = "False" Then
            r = WorksheetFunction.RandBetween(3, 5)
            For ii = 3 To 5
                If ii <> r Then
                    Cells(i, ii).ClearContents
                End If
            Next ii
        End If
    Next i

End Sub

Note that if the values in column Q are the Boolean values FALSE and not the text entry "False", you will need to change that line to this (without the quotes around the word False).
VBA Code:
        If Cells(1, "Q").Value = False Then
 
Upvote 0
Try this:
VBA Code:
Sub test()

    Dim i&, r%, ii%

    For i = 6 To Cells(Rows.Count, "B").End(3).Row
        If Cells(1, "Q").Value = "False" Then
            r = WorksheetFunction.RandBetween(3, 5)
            For ii = 3 To 5
                If ii <> r Then
                    Cells(i, ii).ClearContents
                End If
            Next ii
        End If
    Next i

End Sub

Note that if the values in column Q are the Boolean values FALSE and not the text entry "False", you will need to change that line to this (without the quotes around the word False).
VBA Code:
        If Cells(1, "Q").Value = False Then
I've just tried it, but it does not take column Q into consideration. It still deletes 2/3 forms in every row, not just in the rows where column Q states (boolean) FALSE.
 
Upvote 0
Did you try both the False (without double-quotes) and "False" (with double-quotes) options?
 
Upvote 0
I did. With the quotes nothing happens, without, it still functions like before.
 
Upvote 0
Can you post a screen shot of your data, including at least one row that has this False value?
Be sure that the row numbers and column letters are visible in your screen shot, so I can see where it resides on the sheet.
 
Upvote 0
1731680156840.png


So pupils fill in the irregular forms in columns C, D and E. If it is correct, the cells in column J, K and L change from 0 to 1 to calculate their score. Columns M, N and O are just to check if they filled something in. Column P then checks if they got the maximum score. Column Q will then be a copy of the value of column P. This way, they can keep trying again until they have everything correct. My goal with this macro is that only the rows on which they didn't get the maximum score, they get a new chance. This means that either colum C, D or E is filled in, and they have to add the two others.
For this to work properly, the document will first have to clear all three columns, fill in the correct answer, then randomly delete 2/3 of the answers and reset the score. The only thing that needs fixing, it how to make it look at column Q to decide if it needs to go through these steps or not.

I hope I'm making sense.
 
Upvote 0

Forum statistics

Threads
1,223,932
Messages
6,175,468
Members
452,646
Latest member
tudou

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