---
title: List.InsertRange – แทรก List ลงในตำแหน่งที่ระบุ
url: https://www.thepexcel.com/functions/power-query/list-functions/list-insertrange/
type: function-explainer
program: Power Query
syntax: "List.InsertRange(list as list, index as number, values as list) as list"
date: 2025-12-03
updated: 2025-12-17
scores:
  popularity: 4
  difficulty: 4
  usefulness: 4
---

# List.InsertRange – แทรก List ลงในตำแหน่งที่ระบุ

> แทรก List ลงในตำแหน่งที่ระบุ

## คำอธิบาย

List.InsertRange แทรก List ย่อยเข้าไปใน List หลัก ณ ตำแหน่งที่กำหนด

## Syntax

```excel
List.InsertRange(list as list, index as number, values as list) as list
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| list | Yes | list |  | List หลักที่ต้องการนำข้อมูลมาแทรก |
| index | Yes | number |  | ตำแหน่ง (Index) ที่จะเริ่มแทรกข้อมูล (เริ่มนับที่ 0) |
| values | Yes | list |  | List ของข้อมูลที่ต้องการนำไปแทรก |

## เคสการใช้งาน

### เติมข้อมูลที่ขาดหายไป

แทรกข้อมูลที่ขาดหายไปลงในลำดับที่ถูกต้องของ List

### รวม List แบบระบุตำแหน่ง

รวมข้อมูลจากสองแหล่งเข้าด้วยกันโดยไม่ได้ต่อท้าย (Append) แต่แทรกตรงกลางตามตำแหน่งที่ต้องการ

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: แทรกตัวเลขตรงกลาง

```excel
List.InsertRange({1, 2, 5}, 2, {3, 4})
```

**ผลลัพธ์:** `{1, 2, 3, 4, 5}`

แทรก List `{3, 4}` ลงใน List `{1, 2, 5}` ที่ตำแหน่ง Index 2 (คือหลังเลข 2 และก่อนเลข 5) ผลลัพธ์คือเรียง 1 ถึง 5

### 2. ตัวอย่างที่ 2: แทรกที่ตำแหน่งเริ่มต้น (Index 0)

```excel
List.InsertRange({2, 3, 4}, 0, {1})
```

**ผลลัพธ์:** `{1, 2, 3, 4}`

แทรก `{1}` ที่ตำแหน่งแรกสุด (Index 0) ทำให้ 1 ไปอยู่หน้าสุด

### 3. ตัวอย่างที่ 3: แทรก List ซ้อน List

```excel
List.InsertRange({10, 20}, 1, {{"A", "B"}})
```

**ผลลัพธ์:** `{10, {"A", "B"}, 20}`

แทรก List `{"A", "B"}` (ในฐานะสมาชิกตัวเดียวที่เป็น List) เข้าไปที่ Index 1 ผลลัพธ์คือ List ที่มีสมาชิกผสมกัน (Mixed Types)

## คำถามที่พบบ่อย

**Q: List.InsertRange ต่างจาก List.Combine อย่างไร?**

List.Combine นำ List มาต่อกัน (ต่อท้าย) เท่านั้น แต่ List.InsertRange สามารถแทรกข้อมูลตรงจุดไหนก็ได้ของ List

**Q: ถ้า Index เกินความยาวของ List จะเกิดอะไรขึ้น?**

จะเกิด Error เนื่องจาก Index Out of Range ต้องระบุ Index ที่มีอยู่จริงหรือเท่ากับจำนวนสมาชิก (เพื่อต่อท้าย) เท่านั้น

## ฟังก์ชันที่เกี่ยวข้อง

- [List.Combine – รวม List](https://www.thepexcel.com/functions/power-query/list-functions/list-combine/)
- list-replaceplus
- [List.ReplaceRange – แทนที่ช่วงของรายการ](https://www.thepexcel.com/functions/power-query/list-functions/list-replacerange/)

## แหล่งข้อมูลเพิ่มเติม

- [Microsoft Learn: List.InsertRange](https://learn.microsoft.com/en-us/powerquery-m/list-insertrange) _(Official Documentation)_

---

_Source: [https://www.thepexcel.com/functions/power-query/list-functions/list-insertrange/](https://www.thepexcel.com/functions/power-query/list-functions/list-insertrange/)_
