Create Simple Data Entry in Google Sheets
Bismillah,
Assalamualaikum,
Hello everyone, in this article I will discuss how to make simple data entry in Google Sheets. Data Entry is the process of entering new data into the database. In this tutorial, we will also discuss how to update and delete existing data.
Creating Display
Creating display interface can be done by setting the size of rows and columns, adding background color, adding table lines and setting the size and type of font.
Data validation
In the column to be input, data validation adjustments are made. This feature can be accessed on the Data > Data Validation.
Data Validation for Date
Data Validation for Email
Creating a Button
Creating a button can be done by Insert > Drawing.
Duplication of the drawing button can be done by going to the edit mode of the button you want to copy, select the button, copy with ctrl + C, save and close, then open a new Drawing menu with Insert > Drawing, paste with ctrl + V
Adjust the position of the button on the display .
Gridlines can be removed using the View > Show > Gridlines.
Create a button with the Drawing feature
Display after setting the position of the Button
Gridlines button that has been removed
Creating Database sheet
Database Sheet is used to store data that has been inputted by Data Entry.
The order of the columns is Nickname, Name, Date, Phone, Email and Address.
While the sheet containing the Data Entry is renamed to "User Form"
Change the name of the sheet containing the Data Entry to "User Form"
Display the "Database" Sheet
Create a Save script
Open the Tools menu > Script Editor, if not, please try Extensions > Apps Script.
If the Script Editor or Apps Script is not available, make sure your file is in Google Sheets format, not Excel format, by going to File > Save As Google Sheets.
Please paste the script below in Apps Script.
function submitData (){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formSS = ss.getSheetByName("User Form");
var dataSheet = ss.getSheetByName("Database");
var values = [[
formSS.getRange("D7").getValue(),
formSS.getRange("D9").getValue(),
formSS.getRange("D11").getValue(),
formSS.getRange("D13").getValue(),
formSS.getRange("D15").getValue(),
formSS.getRange("D17").getValue(),
]]
dataSheet.getRange(dataSheet.getLastRow()+1, 1, 1, 6).setValues(values);
formSS.getRange("D7").clear();
formSS.getRange("D9").clear();
formSS.getRange("D11").clear();
formSS.getRange("D13").clear();
formSS.getRange("D15").clear();
formSS.getRange("D17").clear();
SpreadsheetApp.getUi().alert("Data Saved Successfully");
}
Copy the text “submitData”
Click the three dots on the “Save” button, click “Assign script”, paste the text “submitData”.
Assign script on the "Save" button
Create a Clear Script
Please paste the script below into Apps Script.
function clearForm(){
var myGoogleSheets = SpreadsheetApp.getActiveSpreadsheet();
var shUserform = myGoogleSheets.getSheetByName("User Form");
var ui = SpreadsheetApp.getUi();
var response = ui.alert("Reset Confirmation", "Do you want to reset this form?", ui.ButtonSet.YES_NO);
if (response == ui.Button.YES){
shUserform.getRange("D4").clear();
shUserform.getRange("D7").clear();
shUserform.getRange("D9").clear();
shUserform.getRange("D11").clear();
shUserform.getRange("D13").clear();
shUserform.getRange("D15").clear();
shUserform.getRange("D17").clear();
}
}
Copy the text “clearForm”
Click the three dots on the “Clear” button, click “Assign script”, paste the text “clearForm”.
Create a Search script
Please paste the script below into Apps Script.
var SPREADSHEET_NAME = "Database";
var SEARCH_COL_IDX = 0;
var RETURN_COL_IDX = 0;
function searchStr(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formSS = ss.getSheetByName("User Form");
var str = formSS.getRange("D4").getValue();
var values = ss.getSheetByName("Database").getDataRange().getValues();
for (var i = 0; i < values.length; i++) {
var row = values[i];
if (row [SEARCH_COL_IDX] == str ){
formSS.getRange("D7").setValue(row[0]);
formSS.getRange("D9").setValue(row[1]);
formSS.getRange("D11").setValue(row[2]);
formSS.getRange("D13").setValue(row[3]);
formSS.getRange("D15").setValue(row[4]);
formSS.getRange("D17").setValue(row[5]);
return row [RETURN_COL_IDX];
}
}
}
Copy the text “searchStr”
Click the three dots on the “Search” button, click “Assign script”, paste the text “searchStr”.
Create an Update script
Please paste the script below into Apps Script.
function updateData (){
var SPREADSHEET_NAME = "Database";
var SEARCH_COL_IDX = 0;
var RETURN_COL_IDX = 0;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formSS = ss.getSheetByName("User Form");
var dataSheet = ss.getSheetByName("Database");
var str = formSS.getRange("D4").getValue();
var values = ss.getSheetByName("Database").getDataRange().getValues();
for (var i = 0; i < values.length; i++){
var row = values [i];
if (row [SEARCH_COL_IDX] == str){
var INT_R = i+1
var values1 = [[
formSS.getRange("D7").getValue(),
formSS.getRange("D9").getValue(),
formSS.getRange("D11").getValue(),
formSS.getRange("D13").getValue(),
formSS.getRange("D15").getValue(),
formSS.getRange("D17").getValue(),
]];
dataSheet.getRange(INT_R, 1, 1, 6).setValues(values1);
SpreadsheetApp.getUi().alert("Data Updated");
return row [RETURN_COL_IDX];
}
}
}
Copy the text “updateData”
Click the three dots on the “Update” button, click “Assign script”, paste the text “updateData”.
Create a Delete script
Please paste the script below into Apps Script.
function rowDelete (){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formSS = ss.getSheetByName("User Form");
var dataSheet = ss.getSheetByName("Database");
var ui = SpreadsheetApp.getUi();
var response = ui.alert('Delete Confirmation','Are you sure to delete this data?', ui.ButtonSet.YES_NO);
if(response == ui.Button.YES){
var str = formSS.getRange("D4").getValue();
var values = ss.getSheetByName("Database").getDataRange().getValues();
for(var i = 0; i< values.length; i++){
var row = values [i];
if(row [SEARCH_COL_IDX] == str){
var INT_R = i+1
dataSheet.deleteRow(INT_R);
formSS.getRange("D7").clear();
formSS.getRange("D9").clear();
formSS.getRange("D11").clear();
formSS.getRange("D13").clear();
formSS.getRange("D15").clear();
formSS.getRange("D17").clear();
return row [RETURN_COL_IDX];
}
}
}
}
Copy the text “rowDelete”
Click the three dots on the “Delete” button, click “Assign script”, paste the text “rowDelete”.
Thus, a simple data entry tutorial. Hopefully useful, thank you.
Wassalamualaikum
Comments
Post a Comment