Remove content depending of a variable with VBA

Crazyjokerz

New Member
Joined
Feb 23, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi, i'm new with VBA, learning by myself, and i didn't found my answer. I know other language like Python, C for example.

Here is my work :
function ClearCells() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Daily');
sheet.getRange('B3:B5').clearContent();
sheet.getRange('D3:D5').clearContent();
sheet.getRange('B9:B16').clearContent();
sheet.getRange('D9:D16').clearContent();
sheet.getRange('F9:F16').clearContent();
sheet.getRange('H9:H16').clearContent();
sheet.getRange('J9:J16').clearContent();
sheet.getRange('L9:L16').clearContent();
sheet.getRange('N9:N16').clearContent();
sheet.getRange('P9:P16').clearContent();
}

It's quite basic & stupid. I would like to get a loop "for" or "while". like :
for (i going to B to P, i + 2), so that the variable 'i' take the value of B, then D, then F ... until P
and also that my cells ("B3:B5") looks more like ''i''X':'i''X+range')
My problem is that when i add lines before, the code is not following and i have to change it in every line of code.
As i said, i'm new and i basicly know nothing, i'm not asking for explanations, i can dig on internet to understand, but a code quite easy to understand would help me.
Sorry if my english is approximate, i'm doing my best here too :)

Thanks if you took the time to read me
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I forgot to say : I'm working on Spreadsheet google, so every functionalities are not always available or i have to download them.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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