53
Sheet.getRange(1,1,1,12)

I cannot understand the arguments 1,1,1,12 . What is this - the sheet id or row or what?

method getRange(row, column, optNumRows, optNumColumns)

here what does optNumRows and optNumColumns mean???

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Sneha Grewal
  • 581
  • 1
  • 6
  • 8
  • 2
    Thinking logically, the row would be the start row and the optNumRows will be the number of rows from there, and the opt meaning you don't have to specify these parameters, so you could also type in the first 2 parameters without specifying the number of rows/cols (so you get B5 for example). – Terry Aug 14 '12 at 07:33
  • Thanks for the quick reply can you please look this for me http://stackoverflow.com/questions/11946500/i-need-to-copy-data-from-3-sheets-to-another-master-sheet-in-same-spreadsheet – Sneha Grewal Aug 14 '12 at 07:40
  • Maybe this wasn't documented in 2012, but now [`getRange(row, column, numRows, numColumns)` is clearly documented](https://developers.google.com/apps-script/reference/spreadsheet/sheet#getrangerow,-column,-numrows,-numcolumns). – Dan Dascalescu May 15 '23 at 13:35

2 Answers2

91

Found these docu on the google docu pages:

  • row --- int --- top row of the range
  • column --- int--- leftmost column of the range
  • optNumRows --- int --- number of rows in the range.
  • optNumColumns --- int --- number of columns in the range

In your example, you would get (if you picked the 3rd row) "C3:O3", cause C --> O is 12 columns

edit

Using the example on the docu:

// The code below will get the number of columns for the range C2:G8
// in the active spreadsheet, which happens to be "4"
var count = SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getNumColumns(); Browser.msgBox(count);

The values between brackets:
2: the starting row = 2
3: the starting col = C
6: the number of rows = 6 so from 2 to 8
4: the number of cols = 4 so from C to G

So you come to the range: C2:G8

Florent Roques
  • 2,424
  • 2
  • 20
  • 23
Terry
  • 5,132
  • 4
  • 33
  • 66
  • 1
    as per google: // The code below will get the number of columns for the range C2:G8 // in the active spreadsheet, which happens to be "4" var count = SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getNumColumns(); Browser.msgBox(count); – Sneha Grewal Aug 14 '12 at 07:46
  • that's just because they specify an extra call on the getrange, i.e. getNumColumns. you see they have 2,3,6,4 with the 4 being the number of columns in the range, and that's what they show in the msgbox. – Terry Aug 14 '12 at 07:49
  • to add to this answer, once you have the range you can get the values using getValues() (or getValue if you care about a single cell). Besides getting the values you can get many other things, look at the linked doc in the answer. – Zig Mandel Sep 29 '15 at 20:09
  • I have an r1=0 c1=0 r2=3 c2=3 how to get range(0,0,3,3) will give error – Code Guy Apr 24 '17 at 06:32
36

I know this is an older thread but I thought a graphic might help see this visually.

getRange(row, column, optNumRows, optNumColumns)

enter image description here

Migpics
  • 631
  • 7
  • 16