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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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