Page 1 of 1

textbox content to cells merge

Posted: Sat Jan 09, 2021 6:17 am
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

Re: textbox content to cells merge

Posted: Sat Jan 09, 2021 11:46 am
by puriwutpokin
Try

Code: Select all

BottomA=.Range("a"&Rows.Count).End(xlUp).Row+2

Re: textbox content to cells merge

Posted: Sun Jan 10, 2021 6:33 am
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

Re: textbox content to cells merge

Posted: Sun Jan 10, 2021 12:32 pm
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

Re: textbox content to cells merge

Posted: Sun Jan 10, 2021 1:14 pm
by sna
Thank you

Re: textbox content to cells merge

Posted: Sun Jan 10, 2021 10:10 pm
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

Re: textbox content to cells merge

Posted: Sun Jan 10, 2021 10:25 pm
by puriwutpokin
Sample the code post#4 already merge at A2:A3.
What's the problem with the original code?

Re: textbox content to cells merge

Posted: Mon Jan 11, 2021 5:15 am
by sna
It is not working fine

Re: textbox content to cells merge

Posted: Mon Jan 11, 2021 5:17 am
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

Re: textbox content to cells merge

Posted: Mon Jan 11, 2021 10:01 pm
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 🙏