:D snasui.com ยินดีต้อนรับ :D
ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย :thup: สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ :arrow: ระบุ Version ของ Excel
:!: โปรดทราบ :!:
  1. กรุณาอ่านกฎการใช้บอร์ด (Forum rules) ในตำแหน่งด้านบนของแต่ละบอร์ด
  2. การสมัครสมาชิก การ Login การกู้คืนรหัสผ่าน
    1. สมัครสมาชิกดูขั้นตอนได้ที่ :arrow: สมัครสมาชิก
    2. Login เข้าระบบโดยคลิกปุ่ม Login ตรงมุมขวาบนของหน้านี้ :roll:
    3. การ Login ผ่าน Facebook ดูวิธีที่ :arrow: Login ผ่าน Facebook
    4. ลืมรหัสผ่านสามารถรับรหัสใหม่ได้ที่ :arrow: Reset รหัสผ่าน
  3. มีปัญหาการใช้งาน แจ้งผู้ดูแลระบบได้ที่ :arrow: ติดต่อผู้ดูแลระบบ
  4. กำหนดการตั้งค่าส่วนตัว เช่นตั้งค่าภาษาเป็นไทยหรืออังกฤษดูได้ที่ :arrow: ตั้งค่าส่วนตัว
  5. การตั้งและตอบกระทู้ดูได้ที่ :arrow: วิธีการตั้งและตอบกระทู้
  6. การจัดรูปแบบตัวอักษรด้วย bbcode ในช่องแสดงความคิดเห็นดูได้ที่ :arrow: จัดรูปแบบตัวอักษร
  7. กำหนดขนาดตัวอักษรใน Browser ดูได้ที่ :arrow: กำหนดขนาดตัวอักษรใน Browser

textbox content to cells merge

ฟอรัมถาม-ตอบปัญหาการใช้งานสูตรและฟังก์ชัน Excel
Forum rules
  1. ไม่อนุญาตให้ใช้ภาษาแชทในการถามและตอบปัญหา ไม่ใช้คำว่า "คับ" หรือ "อ่ะครับ" แทนคำว่า "ครับ" ไม่ใช้คำว่า "เด๋ว" แทนคำว่า "เดี๋ยว" เป็นต้น เนื่องจากเมื่อแปลเป็นภาษาต่างประเทศแล้วจะให้ความหมายผิดไปจากที่ควรจะเป็น
  2. ห้ามถามโดยระบุชื่อผู้ตอบและต้องตั้งชื่อกระทู้ให้สื่อถึงปัญหาที่จะถาม ไม่ตั้งชื่อว่า ช่วยด้วยครับ, มีปัญหามาปรึกษาครับ เป็นต้น
  3. กรุณาอธิบายปัญหาและระบุคำตอบที่ต้องการมาในกระทู้ด้วยเสมอถึงแม้จะอธิบายไว้ในไฟล์แนบแล้วก็ตาม ทั้งนี้เพื่ออำนวยความสะดวกแก่เพื่อนสมาชิกในการค้นหาข้อมูล
  4. กรุณาแนบไฟล์ตัวอย่างพร้อมแสดงคำตอบที่ถูกต้องมาในไฟล์ด้วยเพื่อให้ง่ายต่อการทำความเข้าใจและสะดวกต่อการตอบคำถาม (ขนาดไฟล์ไม่เกิน 500Kb ขนาดภาพไม่เกิน 800*600 Pixel) ไม่แนบเป็น Link มาจากแหล่งอื่นที่อาจจะถูกลบทิ้งไปโดยต้นทางในภายหลัง นอกจากนี้ไม่ควรแนบไฟล์ที่มีข้อมูลสำคัญอันก่อให้เกิดความเสียหายกับตนเองและผู้อื่น
  5. กรณีเป็นคำถามเกี่ยวกับ Programming เช่น VBA, VB.Net, C#, SQL ฯลฯ ต้องลองเขียนมาเองก่อนเสมอ ถามเฉพาะที่ติดปัญหา ระบุ Module, Procedure ที่ติดปัญหาให้ชัดเจน กรุณาโพสต์ Code ให้แสดงเป็น Code คือเปิดด้วย [code] และปิดด้วย [/code] ตัวอย่างเช่น [code]dim r as range[/code] เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง)
  6. กรุณาแจ้งผลการใช้งานเมื่อได้รับคำตอบว่าตรงกับความต้องการหรือไม่
sna
Silver
Silver
Posts: 721
Joined: Tue May 05, 2020 8:18 am
Excel Ver: Excel 365

textbox content to cells merge

#1

Post by sna »

Hi Dear!
Hopefully You're all doing fine.I need to transfer data from textbox to merge cells.the cells not having merge but when I run code cell itself should merge with value from Textbox1.
I create a code but when click button nothing happened

Code: Select all

Dim BottomA As Long,i As Long
With Sheets("Sheet1")
BottomA=.Range("a"&Rows.Count).End(xlUp).Row
For i=2 To BottomA Step 2
.Range("a"&i &":a"&i+1).Merge
.Range("a"&i).MergeArea.Value=Me.TextBox1.Value
Next 
End with
I wait for your kind response
Thank you in advance
You do not have the required permissions to view the files attached to this post.
User avatar
puriwutpokin
Guru
Guru
Posts: 3801
Joined: Fri Jan 04, 2013 9:49 pm
Location: Bangkok
Excel Ver: MS.365

Re: textbox content to cells merge

#2

Post by puriwutpokin »

Try

Code: Select all

BottomA=.Range("a"&Rows.Count).End(xlUp).Row+2
:shock: :roll: :D
sna
Silver
Silver
Posts: 721
Joined: Tue May 05, 2020 8:18 am
Excel Ver: Excel 365

Re: textbox content to cells merge

#3

Post by sna »

Thanks but I need that if I type hi it will merge a2:a3 ,I type hello a4:a5, good a6:a7 and so on

Thanks
User avatar
puriwutpokin
Guru
Guru
Posts: 3801
Joined: Fri Jan 04, 2013 9:49 pm
Location: Bangkok
Excel Ver: MS.365

Re: textbox content to cells merge

#4

Post by puriwutpokin »

Sample code

Code: Select all

With Sheets("KONTRAK")
bottomA = .Range("A" & Rows.Count).End(xlUp).Row + 2
If .Range("a2").Value = "" Then
.Range("a2:a3").Merge
.Range("a2").Value = Me.TextBox1.Text
Else
For i = 2 To bottomA Step 2
.Range("a" & i & ":a" & i + 1).Merge
.Range("a" & bottomA).Value = Me.TextBox1.Text
Next i
End If
Me.TextBox1.Text = ""
End With
:shock: :roll: :D
sna
Silver
Silver
Posts: 721
Joined: Tue May 05, 2020 8:18 am
Excel Ver: Excel 365

Re: textbox content to cells merge

#5

Post by sna »

Thank you
sna
Silver
Silver
Posts: 721
Joined: Tue May 05, 2020 8:18 am
Excel Ver: Excel 365

Re: textbox content to cells merge

#6

Post by sna »

I have turn code to the below.i try to start merge at a2 but no luck
here's my code,how to fix it

Code: Select all

Sub test()
With Sheets ("Sheet1")
Dim BottomA As Long,i As Long
BottomA=.Range("a"&Rows.Count).End(xlUp).Row
n=BottomA
. Range ("a"&i+2 & ":a"&i+3).Merge
. Range ("a"&i+2).MergeArea.Value=Me.TextBox1.Text
End With
Thanks
User avatar
puriwutpokin
Guru
Guru
Posts: 3801
Joined: Fri Jan 04, 2013 9:49 pm
Location: Bangkok
Excel Ver: MS.365

Re: textbox content to cells merge

#7

Post by puriwutpokin »

Sample the code post#4 already merge at A2:A3.
What's the problem with the original code?
:shock: :roll: :D
sna
Silver
Silver
Posts: 721
Joined: Tue May 05, 2020 8:18 am
Excel Ver: Excel 365

Re: textbox content to cells merge

#8

Post by sna »

It is not working fine
sna
Silver
Silver
Posts: 721
Joined: Tue May 05, 2020 8:18 am
Excel Ver: Excel 365

Re: textbox content to cells merge

#9

Post by sna »

The code wrong typo should be but it isn't starting in a2

Code: Select all

Sub test()
With Sheets ("Sheet1")
Dim BottomA As Long,i As Long
BottomA=.Range("a"&Rows.Count).End(xlUp).Row
i=BottomA
. Range ("a"&i+2 & ":a"&i+3).Merge
. Range ("a"&i+2).MergeArea.Value=Me.TextBox1.Text
End With
sna
Silver
Silver
Posts: 721
Joined: Tue May 05, 2020 8:18 am
Excel Ver: Excel 365

Re: textbox content to cells merge

#10

Post by sna »

Thanks puriwutpokin
I forget add 2 to bottomA
bottomA = .Range("A" & Rows.Count).End(xlUp).Row + 2

Now it is working fine...

Thank you 🙏
Post Reply