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
 
Oh sorry, I made a typo!

This line:
VBA Code:
        If Cells(1, "Q") = False Then
should actually be this:
VBA Code:
        If Cells(i, "Q") = False Then
otherwise it is always looking at row 1, instead of whatever row i is at the time!
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Oh sorry, I made a typo!

This line:
VBA Code:
        If Cells(1, "Q") = False Then
should actually be this:
VBA Code:
        If Cells(i, "Q") = False Then
otherwise it is always looking at row 1, instead of whatever row i is at the time!
Thanks, that made it work. I was already trying to make sense of the code, and I couldn't figure out what the 1 was referring to. I need to find a VBA for beginners manual 😆
 
Upvote 0
You are welcome.

"Cells" is another range object like "Range", i.e.
the format is
Cells(row, column)

So
Cells(1, "Q")
would be the same as:
Range("Q1")

The big advantage to Cells over Range, is that you can use either a number or a letter in the column argument.
So, since "Q" is the 17th column on the worksheet, this:
Cells(1, 17)
is the same as this:
Cells(1, "Q")

BTW, there are some good VBA books over in the MrExcel Bookstore, like this one here: Microsoft Excel VBA and Macros (Office 2021 and Microsoft 365)
 
Upvote 0

Forum statistics

Threads
1,223,933
Messages
6,175,473
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