getlastrow, then last column, and then populate based on that information

Viewed 51

Recently, there was a program by the name of Eddienuput that allows you to properly train against basically anything in training mode. One issue is that you have to make a text file with all the button presses, as well as the timing for each. Once this text file is made, the inputs are added into a virtual controller.

The working sheet can be seen here.

The idea here is that you put the data of the character on the second sheet, then on the generator sheet you select the buttons you want, then press the [>] to put it to the right of the current buttons stored, and you use the [v] button.

When I hit the down arrow (I've assigned the script to the buttons), the three entries needed for the program to register the input are inserted one row below the active row.

The problem is the Right arrow. I sort of have it right (it puts the three inputs needed to the right.. but it isn't finding the bottom-right entry and putting it to the right of it, but instead it looks for the furthest right column and puts it to the right of everything instead of next to the last cell on the last row.

here is the code as I have it now:

function addbuttontoString()
{
  //DEFINE ALL ACTIVE SHEETS
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var eddGenSheet = ss.getSheetByName("Eddie Input Generator");
  var lrwithcontentofEddGenSheet = eddGenSheet.getLastRow()+1;
  var lcwithcontentofEddGenSheet = eddGenSheet.getLastColumn();

  var CharacterFrameDataSheet = ss.getSheetByName("CharacterFrameData");
  
  //Current string Variables 
  var totalcurrentstringRows = lrwithcontentofEddGenSheet-4;
  var fullcurrentString = eddGenSheet.getRange(5,1,totalcurrentstringRows, lcwithcontentofEddGenSheet);

  var cslastRow = fullcurrentString.getLastRow();
  var bottomrightcolumnNumber = eddGenSheet.getRange(lrwithcontentofEddGenSheet,1,1,lcwithcontentofEddGenSheet).getLastColumn();


Logger.log(bottomrightcolumnNumber)
  //GET LAST ROW #OF ITEM SHEET
  var lastrowItem = CharacterFrameDataSheet.getLastRow();
  
  // Get the perfect Eddie value from Character Frame Data you are grabbing data for
  var button = eddGenSheet.getRange('B4').getValue();
  
  // Set up the Perfect Frame Variable
  for(var i = 2; i <= lastrowItem; i++)
  {
    if(button == CharacterFrameDataSheet.getRange(i, 1).getValue())
    {
      var Perfectframe = CharacterFrameDataSheet.getRange(i, 4).getValue();
    }
  }
  Logger.log(fullcurrentString.isBlank());

  if(fullcurrentString.isBlank()){
  // POPULATE eddGen SHEET Same Line
  eddGenSheet.getRange("A5").setValue(button);
  eddGenSheet.getRange("B5").setValue("F");
  eddGenSheet.getRange("C5" ).setValue(Perfectframe);
  } else {
  eddGenSheet.getRange(lrwithcontentofEddGenSheet-1, bottomrightcolumnNumber +1).setValue(button);
  eddGenSheet.getRange(lrwithcontentofEddGenSheet-1, bottomrightcolumnNumber +2).setValue("W");
  eddGenSheet.getRange(lrwithcontentofEddGenSheet-1, bottomrightcolumnNumber +3).setValue(Perfectframe);
  }
}
1 Answers

I believe your goal as follows.

  • When you click the right arrow button, you want to add the values from the 1st empty column of the row.

In your script, in order to retrieve the coordinate of the column for putting values, getLastColumn() is used as follows. In this case, the 1st empty column of the row is not retrieved. The last column of the sheet is retrieved. So, how about the following modification?

From:

var bottomrightcolumnNumber = eddGenSheet.getRange(lrwithcontentofEddGenSheet,1,1,lcwithcontentofEddGenSheet).getLastColumn();

To:

var bottomrightcolumnNumber = eddGenSheet.getRange(lrwithcontentofEddGenSheet - 1, 1).getNextDataCell(SpreadsheetApp.Direction.NEXT).getColumn();
  • In this modification, the 1st empty column is retrieved using getNextDataCell().

Note:

  • I'm not sure about your actual situation. So when above modification was not useful for your situation, can you provide the detail information about your actual situation? By this, I would like to modify it.

References:

Related