I have a range of cells that are merged named "descr": ($B$2:$K$2).
I had a problem (which I fixed) in which you can't pasted certain data to the merged range of cells. The following error messages would pop up when trying to paste:
"Data on clipboard is not the same size and shape as the selected area. Do you want to paste the data anyway?"
<I click OK>
"Can't change part of a merged cell."
<I click OK>
"Microsoft Excel cannot past the data."
So my solution was:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = Range("descr"
.Address Then
SendKeys ("{F2}"
SendKeys ("^+{HOME}"
Application.OnKey "~", "AutoFitMergedCellRowHeight"
End If
End Sub
This is nice, because it select all the data already present in the range, and I can just paste right over it.
Here's my problem now:
After I hit enter to leave the cell, I expect it to trigger the Worksheet_Change event. It doesn't happen though. Apparently, when you enter data directly in the formula bar (which is basically what I'm doing when I SenKeys "F2"
, it doesn't trigger this event. It only triggers the event if you enter data when you click on the cell and type or paste it to the cell.
Any ideas how to get this to get it to trigger an event so I can run my sub? FYI: My sub is just to resize the merged range to fit all the data I've pasted.
I had a problem (which I fixed) in which you can't pasted certain data to the merged range of cells. The following error messages would pop up when trying to paste:
"Data on clipboard is not the same size and shape as the selected area. Do you want to paste the data anyway?"
<I click OK>
"Can't change part of a merged cell."
<I click OK>
"Microsoft Excel cannot past the data."
So my solution was:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = Range("descr"
SendKeys ("{F2}"
SendKeys ("^+{HOME}"
Application.OnKey "~", "AutoFitMergedCellRowHeight"
End If
End Sub
This is nice, because it select all the data already present in the range, and I can just paste right over it.
Here's my problem now:
After I hit enter to leave the cell, I expect it to trigger the Worksheet_Change event. It doesn't happen though. Apparently, when you enter data directly in the formula bar (which is basically what I'm doing when I SenKeys "F2"
Any ideas how to get this to get it to trigger an event so I can run my sub? FYI: My sub is just to resize the merged range to fit all the data I've pasted.