I would like to erase all the data of a sheet in a google sheet
via the googlet sheets APIs: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/clear
Unfortunately I can not select the id of my sheet.
I used the proposed method: POST https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetid}/values/{range}: clear
but it only removes the data from my first sheet.
How can I put the id of my other leaves in the method?
My google sheets ID
My first sheets in my google sheets
ID of my second sheets
My second sheets in my google sheets
From your reply, the request of "Method: spreadsheets.values.clear" is as follows.
POST https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/{range}:clear
spreadsheetId : The spreadsheet the updates were applied to.
range: The range (in A1 notation) that was cleared. (If the request was for an unbounded range or a ranger larger than the bounds of the sheet, this will be the actual range that was cleared, bounded to the sheet's limits.)
In this case, it is not required to use the sheet ID. The sheet name is used.
From your showing images, it seems that the sheet names of your 1st and 2nd sheet are Feuille 1 and Feuille 2, respectively. For example, when you want to clear 2nd sheet of Feuille 2, please use the following request.
POST https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/Feuille%202:clear
Note:
For example, when you want to retrieve the sheet names from a Google Spreadsheet, you can use "Method: spreadsheets.get". Ref
Reference:
Method: spreadsheets.values.clear
Related
Please tell me how in the Google Sheets API you can not manually get the range of the entire table located on a certain sheet.
I have a table in which the number of columns can change, but I still have to get information from it.
sheet = service.spreadsheets().values().get(
spreadsheetId=spreadsheet_id, range='???').execute()
You can you sheet.getDataRange() to get range of the visible data on your spreadsheet.
solution:
sheet = service.spreadsheets().values().get(
spreadsheetId=spreadsheet_id,
range='Sheet1',
majorDimension='ROWS').execute()
I've noticed a slight anomolae in Google Sheets v4 API when adding multiple sheets. When adding a sheet that refers to a non-existant sheet (yet created) when you go in and view the sheet once all are added the formula produces an error - even if the later sheet is in fact now present.
Steps to reproduce:
Add a sheet to a workbook that references in a formula 'Named Table'
Add a sheet called 'Named Table'
The formula in Sheet 1 will error. Go into the cell and hit return and the calculation refreshes (even though nothing has changed) and it will work fine.
Question: Can this refresh process be programatically triggered for Sheets API v4 ?
It can be triggered by the API today by doing the same thing the UI is doing -- read the value in the cell & apply an update to that cell with the same value.
I am trying to move data from one workbook 'input worksheet' to another workbook 'master workbook'. Both sheets are in the same file and if possible, it would be great if both files didn't have to be open at the same time in order to transfer the data but the master workbook would autosave once the data was transferred across. Links to images of the files below to make it easier to understand what I am trying to do.
The data in the input worksheet is in row 6, columns A-J with each user inputting details of the tasks they get asked to complete. I would like when a button is clicked, the data from the input worksheet is transferred into row 2, columns B-K in the master workbook so that each time a new task is entered and transferred across, it appears in the row below (so that it can be pivoted later, etc.).
http://i.stack.imgur.com/b2cyI.jpg - input sheet
http://i.stack.imgur.com/JZr0a.jpg - master sheet
Use the macros here to get the last row in the master sheet.
Then simply write the values from the input sheet to the corresponding cell in the master sheet.
That is all. This is how you refer cells:
tbl_master.cells(1,3) = tbl_input.cells(3,5).value
Make sure that the row in the tbl_input is a variable, coming from the function, calculating the last row. Give it a try!
Edit:
This is what I use for last row:
Public Function last_row_with_data(ByVal lng_column_number As Long, shCurrent As Variant) As Long
last_row_with_data = shCurrent.Cells(Rows.Count, lng_column_number).End(xlUp).Row
End Function
If you want to find the last row of column B of sheet "tbl_main" you call it like this:
last_row_with_data(2,tbl_main)
Edit2:
Change the names of your sheets here, and reference them by their names.
In order to get this window, select the sheet on the left and press F4.
I'm working on automating a workbook in Excel, and I'm running into a few issues with my VBA code. I'd paste it here, but I've been through so many iterations, it's pretty unusable.
The goal is to have the active book 'grab' the data out of several workbooks containing raw data when it is opened, and put the copied data into a few tabs that can be used to populate various charts on a dashboard tab. Each workbook containing raw data should go into its own separate tab within the active workbook. Broken into steps, I am thinking I need the below process to occur:
Open Active Book
Open hidden tab 'Sheet1'
Open raw data book 1(e.g. c:\Raw Data.xls)
Copy data from specified location (e.g. [Raw Data.xls]Sheet1!$A$3:$AE$64) in the raw data book 1
Paste copied data into Active Book, into specific worksheet, into first empty row (e.g. [Active Book.xls]Sheet1!first empty row)
Hide tab 'Sheet1' in Active Book
Close raw data book 1
Repeat process using raw data book 2 and sheet2 of Active Book
Repeat process using raw data book 3 and sheet3 of Active Book
Only after data is populated into the destination tabs (Sheet1, Sheet2, Sheet3 in the Active Book), can the user interact (click into cells, change tabs, etc) with the workbook
I know this is simple - I'm getting frustrated, as I'm a newbie and the syntax (and multiple variations of syntax) is really throwing me for a loop. Any help would be greatly appreciated. Many thanks in advance!!
Where are you getting stuck? Briefly:
Open Active Book
If its active, it's already open? Reference with object 'ThisWorkbook'
Open hidden tab 'Sheet1'
You don't need to unhide sheets to "VBA" them... If you're going to be creating new sheets for each datafile I'd recommend creating new via:
Set wsDestination = thisworkbook.sheets.add
wsDestination.visible = xlSheetHidden ' Might as well hide it now
If you're wanting to match specific raw data files with specific worksheets, maybe use a "select"
Open raw data book 1(e.g. c:\Raw Data.xls)
Set wbSource = Application.Workbooks.Open("c:\Raw Data.xls")
Set wsSource = wbSource.sheets(1)
'If need Select (see above):
Select case wbSource.name
Case "Raw Data A.xls" ' If line above changes to .Open(Workbooks[i]) or something
set wsDestination = sheet1
Case "Raw Data B.xls"
set wsDestination = sheet2
'...
End Select
Copy data from specified location (e.g. [Raw
Data.xls]Sheet1!$A$3:$AE$64) in the raw data book 1 Paste copied data
into Active Book, into specific worksheet, into first empty row (e.g.
[Active Book.xls]Sheet1!first empty row)
intBlankRow = Application.WorksheetFunction.Counta(wsDestination.columns(1)) + 1 ' Note this only works if there are no blanks in column 1 otherwise you'll need another method: there are some good tricks if you google "find last cell vba"
wsSource.cells.copy wsDestination.cells(intBlankRow,1) ' No need to copy and paste in seperate lines: you can just pass destination to the copy function
Hide tab 'Sheet1' in Active Book
You don't need to
Close raw data book 1
wbSource.close
Repeat process using raw data book 2 and sheet2 of Active Book Repeat
process using raw data book 3 and sheet3 of Active Book Only after
data is populated into the destination tabs (Sheet1, Sheet2, Sheet3 in
the Active Book), can the user interact (click into cells, change
tabs, etc) with the workbook
Wrap the whole thing in a big loop... If you wanna do it the easy way, create an array with your workbook names and iterate through it. Otherwise present the user with a FileDialogue so they can select the workbooks they want to import... this ofcourse depends on what I was saying above: do you want to create new worksheets each time or import specific raw data in to specific sheets...
I am very new to vba and need your assistance in writing a code that will do the following
1) I have a workbook titles "workbook.xlms" which I have saved in my documents
2) The workbook has got 2 sheets, namely sheet1 and sheet2
3) Sheet1 has predefined fields such
as "name", "surname", "address", "contact", "social security", "race" and so on
4) After filling in the predefined fields with required data and clicking save, some (or all) of the fields must be written to empty row on sheet 2 sheet2.
5) If new information is filled in on sheet1 and the social security number entered is already registered in sheet2, then new data must not be written to sheet2 (To avoid duplicates).
I do not have any code to share with you and am hoping you can help
Start by recording the copy/paste portion of the macro and view the code. See if you can modify that to suit your needs. Post back here with what you tried if you still can't make it work.