---
title: Text.ReplaceRange – แทนที่ข้อความในช่วงที่ระบุ
url: https://www.thepexcel.com/functions/power-query/text-functions/text-replacerange/
type: function-explainer
program: Power Query
syntax: "Text.ReplaceRange(text as nullable text, offset as number, count as number, newText as text) as nullable text"
date: 2025-12-04
updated: 2025-12-17
scores:
  popularity: 4
  difficulty: 4
  usefulness: 4
---

# Text.ReplaceRange – แทนที่ข้อความในช่วงที่ระบุ

> แทนที่ข้อความในช่วงที่ระบุ

## คำอธิบาย

Text.ReplaceRange ใช้สำหรับแทนที่อักขระในช่วงที่กำหนดด้วยข้อความใหม่ สามารถใช้ลบหรือแทรกข้อความ

## Syntax

```excel
Text.ReplaceRange(text as nullable text, offset as number, count as number, newText as text) as nullable text
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| text | Yes | nullable text |  | ข้อความต้นฉบับ |
| offset | Yes | number |  | ตำแหน่งเริ่มต้นของการแทนที่ |
| count | Yes | number |  | จำนวนอักขระที่ต้องการแทนที่ |
| newText | Yes | text |  | ข้อความใหม่ที่ต้องแทรก |

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

### แก้ไขส่วนของข้อความที่กำหนด

แก้ไขส่วนของข้อความที่กำหนด

### แทนที่อักขระในตำแหน่งที่ระบุ

แทนที่อักขระในตำแหน่งที่ระบุ

### ปรับปรุงข้อความตามรูปแบบ

ปรับปรุงข้อความตามรูปแบบ

## ตัวอย่าง

### 1. แทนที่ HELLO ด้วย HI

```excel
Text.ReplaceRange("HELLO WORLD", 0, 5, "HI")
```

**ผลลัพธ์:** `HI WORLD`

แทนที่ 5 ตัวแรก 'HELLO' ด้วย 'HI'

### 2. แทนที่ WORLD ด้วย UNIVERSE

```excel
Text.ReplaceRange("HELLO WORLD", 6, 5, "UNIVERSE")
```

**ผลลัพธ์:** `HELLO UNIVERSE`

แทนที่ 'WORLD' (5 ตัว) ด้วย 'UNIVERSE'

### 3. แทรกโดยไม่ลบ

```excel
Text.ReplaceRange("ABCD", 2, 0, "XX")
```

**ผลลัพธ์:** `ABXXCD`

แทรก 'XX' ที่ตำแหน่ง 2 โดยไม่ลบตัวใด

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

- [Text.RemoveRange – ลบข้อความจากช่วงที่ระบุ](https://www.thepexcel.com/functions/power-query/text-functions/text-removerange/)
- [Text.Insert – แทรกข้อความ](https://www.thepexcel.com/functions/power-query/text-functions/text-insert/)
- [Text.Replace – แทนที่ข้อความใน Power Query](https://www.thepexcel.com/functions/power-query/text-functions/text-replace/)

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

- [Microsoft Learn: Text.ReplaceRange](https://learn.microsoft.com/en-us/powerquery-m/text-replacerange) _(Official Documentation)_

---

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