i am trying to make a macro that can:
For example: The macro is searchig for the word "Yes" in column E, the word "Yes" is found in E5, copy and paste "Yes" to B5, merge B5 and C5 and confirm the merging (excell always displays a pop un window asking to manually click on the button to confirm the merging), continue with next search.
Please, try the next code. It will not ask anything when merging cells and the area will take the left cell value (B = Yes). If you need the value in C, or a concatenation between the two cells, you must tell us that:
Sub testMergeYesWord()
Dim sh As Worksheet, lastR As Long, i As Long
Set sh = ActiveSheet 'use here the sheet you need
lastR = sh.Range("E" & rows.count).End(xlUp).row
For i = 2 To lastR
If UCase(sh.Range("E" & i).Value) = "YES" Then
sh.Range("B" & i).Value = sh.Range("E" & i).Value
Application.DisplayAlerts = False 'to avoid the message asking what value to be allocate to the merged area
sh.Range("B" & i & ":C" & i).merge
Application.DisplayAlerts = True
End If
Next i
MsgBox "Ready..."
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.