End

対象セル範囲の領域における終端のRangeオブジェクトへの参照を返します。「[End] + 矢印キー」を押す操作と同等です。

構文
Range = Range.End( Direction )
引数
Direction
移動する方向です。XlDirection定数。
戻値

定数一覧

XlDirection

名前説明
xlUp-4162上へ
xlToRight-4161右へ
xlToLeft-4159左へ
xlDown-4121下へ
CONST xlUp = -4162
CONST xlToRight = -4161
CONST xlToLeft = -4159
CONST xlDown = -4121

プログラム実行例

A列の最終行から上方向の終端セルを選択*

CONST xlUp = -4162

Excel.Cells(Rows.Count, 1).End(xlUp).Select
  1. com.Excel.Range.End(3)

1行目の最終列から左方向の終端セルを選択*

CONST xlToLeft = -4159

Excel.Cells(1, Columns.Count).End(xlToLeft).Select
  1. com.Excel.Range.End(3)

A1セルから右下方向の終端セルを選択*

A1セルが表の先頭であり空白データがない場合、表の右下のセルを選択できます。

CONST xlDown = -4121
CONST xlToRight = -4161

Excel.Range("A1").End(xlDown).End(xlToRight).Select
  1. com.Excel.Range.End(3)

気象庁のホームページから一月分の気温を取得しExcelでグラフを作成

CONST xlUp = -4162
CONST xlLineMarkers = 65

DIM year = 2020
DIM month = 8

DIM IE = IEBoot()
IE.Navigate("https://www.data.jma.go.jp/obd/stats/etrn/view/daily_s1.php?prec_no=14&block_no=47412&year=" + year + "&month=" + month + "&day=&view=p1")
BusyWait(IE)

DIM array[-1][-1]
DIM element = IE.document.getElementById("tablefix1")
getTableData(element, array)

IE.Quit

DIM Excel = XLOPEN()
DIM SheetName = Excel.ActiveSheet.Name

XLSETDATA(Excel, array, "A1")

DIM row = Excel.Cells(Excel.Rows.Count, 1).End(xlUp).Row
DIM Charts = Excel.Charts.Add

WITH Charts
	.ChartType = xlLineMarkers
	.SeriesCollection.NewSeries
	.HasTitle = TRUE
	.ChartTitle.Text = "札幌 " + year + "年" + month + "月気温"

	WITH .FullSeriesCollection(1)
		.XValues = "=Sheet1!$A$5:$A$35"
		.Name = "=<#DBL>最高気温<#DBL>"
		.Values = "=Sheet1!$H$5:$H$35"
		WITH .Format
			.Fill.ForeColor.RGB = 255
			.Line.ForeColor.RGB = 255
		ENDWITH
	ENDWITH

	WITH .FullSeriesCollection(2)
		.XValues = "=Sheet1!$A$5:$A$35"
		.Name = "=<#DBL>最高気温<#DBL>"
		.Values = "=Sheet1!$I$5:$I$35"
		WITH .Format
			.Fill.ForeColor.RGB = 16711680
			.Line.ForeColor.RGB = 16711680
		ENDWITH
	ENDWITH
ENDWITH

//////////////////////////////////////////////////
// 【引数】
//   IE : IEオブジェクト 
// 【戻値】
// 
//////////////////////////////////////////////////
PROCEDURE BusyWait(Var IE)
	SLEEP(0.500)
	DIM t = GETTIME()
	TRY
		REPEAT
			DIM tm = GETTIME() - t
			FUKIDASI("BusyWait:" + tm)
			SLEEP(0.010)
			IF tm >= 60 THEN BREAK
		UNTIL !IE.Busy AND IE.readyState = 4
	EXCEPT
		IE = getIEObj(-1)
		PRINT IE.document.URL + " のIEオブジェクトを取得しました。"
		BusyWait(IE)
	ENDTRY
	FUKIDASI()
FEND

//////////////////////////////////////////////////
// 【引数】
//   文字列 or 数値 : 取得したいIEオブジェクトのタイトル・URLもしくは数値を指定 
//   完全一致フラグ : (TRUE : 文字列が完全一致したものを取得、FALSE : 文字列の一部を含むものを取得) 
// 【戻値】
//   Internet Explorerオブジェクト 
//////////////////////////////////////////////////
FUNCTION getIEObj(str, flg = FALSE)
	DIM Shell = CREATEOLEOBJ("Shell.Application")
	SELECT CHKNUM(str)
		CASE TRUE
			DIM cnt = 0
			SELECT TRUE
				CASE str > 0
					FOR n = 0 TO Shell.Windows.Count - 1
						TRY
							IFB Shell.Windows.Item(n).Name = "Internet Explorer" THEN
								cnt = cnt + 1
								IFB str = cnt THEN
									RESULT = Shell.Windows.Item(n)
									EXIT
								ENDIF
							ENDIF
						EXCEPT
						ENDTRY
					NEXT
				CASE str < 0
					FOR n = Shell.Windows.Count - 1 TO 0 STEP -1
						TRY
							IFB Shell.Windows.Item(n).Name = "Internet Explorer" THEN
								cnt = cnt + 1
								IFB ABS(str) = cnt THEN
									RESULT = Shell.Windows.Item(n)
									EXIT
								ENDIF
							ENDIF
						EXCEPT
						ENDTRY
					NEXT
				CASE str = 0
					FOR n = 0 TO Shell.Windows.Count - 1
						TRY
							IF Shell.Windows.Item(n).Name = "Internet Explorer" THEN cnt = cnt + 1
						EXCEPT
						ENDTRY
					NEXT
					RESULT = cnt
					EXIT
			SELEND
		CASE FALSE
			DIM t = GETTIME()
			REPEAT
				FOR n = 0 TO Shell.Windows.Count - 1
					TRY
						DIM targetObj = Shell.Windows.Item(n)
						IFB targetObj.Name = "Internet Explorer" THEN
							SELECT flg
								CASE TRUE
									IFB targetObj.document.title = str OR targetObj.LocationURL = str THEN
										RESULT = Shell.Windows.Item(n)
										EXIT
									ENDIF
								CASE FALSE
									IFB POS(str, targetObj.document.title) OR POS(str, targetObj.LocationURL) THEN
										RESULT = Shell.Windows.Item(n)
										EXIT
									ENDIF
							SELEND
						ENDIF
					EXCEPT
					ENDTRY
				NEXT
			UNTIL GETTIME() - t >= 5
	SELEND
	RESULT = ERR_VALUE
FEND

//////////////////////////////////////////////////
// 【引数】
//   table : tableエレメント 
//   arr : 取得したデータを格納する配列(参照引数) 
// 【戻値】
// 
//////////////////////////////////////////////////
PROCEDURE getTableData(table, Var arr[][])
	rowMax = table.rows.length - 1
	colMax = 0
	FOR row = 0 TO table.rows.length - 1
		IFB table.rows(row).cells.length - 1 > colMax THEN
			colMax = table.rows(row).cells.length - 1
		ENDIF
	NEXT
	DIM arr[rowMax][colMax]
	FOR row = 0 TO table.rows.length - 1
		FOR col = 0 TO table.rows(row).cells.length - 1
			n = 0
			WHILE arr[row][col + n] <> ""
				n = n + 1
			WEND
			arr[row][col + n] = table.rows(row).cells(col).innerText
			// rowSpan(行結合)とcolSpan(列結合)の両方があれば
			IFB table.rows(row).cells(col).rowSpan > 1 AND table.rows(row).cells(col).colSpan > 1 THEN
				rmax = table.rows(row).cells(col).rowSpan - 1
				cmax = table.rows(row).cells(col).colSpan - 1
				FOR r = 1 TO rmax
					FOR c = 1 TO cmax
						arr[row + r][col + c] = "←"
					NEXT
				NEXT
			ENDIF
			// rowSpan(行結合)があれば結合セルに「↑」を代入
			IFB table.rows(row).cells(col).rowSpan > 1 THEN
				n = table.rows(row).cells(col).rowSpan - 1
				WHILE n
					arr[row + n][col] = "↑"
					n = n - 1
				WEND
			ENDIF
			// colSpan(列結合)があれば結合セルに「←」を代入
			IFB table.rows(row).cells(col).colSpan > 1 THEN
				n = table.rows(row).cells(col).colSpan - 1
				WHILE n
					arr[row][col + n] = "←"
					n = n - 1
				WEND
			ENDIF
		NEXT
	NEXT
FEND

//////////////////////////////////////////////////
// 【引数】
//   InPrivate : InPrivateブラウズ・モードを有効にするときはTRUEを指定(デフォルトはFALSE) 
// 【戻値】
//   InternetExplorerオブジェクト 
//////////////////////////////////////////////////
FUNCTION IEBoot(InPrivate = FALSE)
	DIM IE
	SELECT InPrivate
		CASE TRUE
			DOSCMD("start iexplore -private")
			GETID("InPrivate - Internet Explorer - [InPrivate]", "IEFrame", -1)
			IE = GETACTIVEOLEOBJ("InternetExplorer.Application","InPrivate - Internet Explorer - [InPrivate]")
		CASE FALSE
			TRY
				IE = CREATEOLEOBJ("InternetExplorer.Application")
				IE.Visible = TRUE
			EXCEPT
				EXEC("C:\Program Files\Internet Explorer\iexplore.exe")
				GETID("Internet Explorer", "IEFrame", -1)
				TRY
					IE = GETACTIVEOLEOBJ("InternetExplorer.Application")	
				EXCEPT
					IE = getIEObj(-1)
				ENDTRY
			ENDTRY
	SELEND
	RESULT = IE
FEND
  1. udf.IEBoot(7)
  2. com.IE.Navigate(8)
  3. udf.BusyWait(9)
  4. dom.document.getElementById(12)
  5. udf.getTableData(13)
  6. script.function.XLOPEN(17)
  7. com.Excel.Application.ActiveSheet(18)
  8. com.Excel.WorkSheet.Name(18)
  9. script.function.XLSETDATA(20)
  10. com.Excel.Application.Cells(22)
  11. com.Excel.Range.End(22)
  12. com.Excel.Range.Row(22)
  13. com.Excel.Application.Charts(23)
  14. com.Excel.Sheets.Add(23)
  15. com.Excel.Charts(25)
  16. com.Excel.Chart.ChartType(26)
  17. com.Excel.Chart.SeriesCollection(27)
  18. com.Excel.Series(27)
  19. com.Excel.Chart.HasTitle(28)
  20. com.Excel.Chart.ChartTitle(29)
  21. com.Excel.FullSeriesCollection(31,41)
  22. com.Excel.FullSeriesCollection.Item(31,41)
  23. com.Excel.Series.XValues(32,42)
  24. com.Excel.Series.Name(33,43)
  25. com.Excel.Series.Values(34,44)
  26. com.Excel.Series.Format(35,45)
  27. com.Excel.FillFormat.ForeColor(36,46)
結果