I have a code where i am highlighting a cell in a worksheet (Step 1 - Manifold), clicking a commandbutton, then the value that was highlighted copies over to another worksheet (Smart Calc).
It works great but the issue is that some of the cells that you highlight are merged. This means for instance that if the cell you selected was merged with 3 cells, the script thinks you are highlighting 3 cells and therefore copies the data 3 times to the other worksheet.
Is there a way that my code can work to only copy / paste the selected data once to the other worksheet?
Here is my code:
Private Sub CommandButton1_Click()
Dim c As Variant
Dim cValue As Variant
Dim test As Variant
Application.DisplayAlerts = False
Application.EnableEvents = False
For Each c In Selection.Cells
Worksheets("Step 1 - Manifold 8640").Activate
c.Activate
test = ActiveCell.Value
Worksheets("Smart Calc").Activate
Worksheets("Smart Calc").Range("A10").Select
Do While ActiveCell.Value <> ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = test
Next
Application.DisplayAlerts = False
Application.EnableEvents = False
Worksheets("Step 1 - Manifold 8640").Activate
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
It works great but the issue is that some of the cells that you highlight are merged. This means for instance that if the cell you selected was merged with 3 cells, the script thinks you are highlighting 3 cells and therefore copies the data 3 times to the other worksheet.
Is there a way that my code can work to only copy / paste the selected data once to the other worksheet?
Here is my code:
Private Sub CommandButton1_Click()
Dim c As Variant
Dim cValue As Variant
Dim test As Variant
Application.DisplayAlerts = False
Application.EnableEvents = False
For Each c In Selection.Cells
Worksheets("Step 1 - Manifold 8640").Activate
c.Activate
test = ActiveCell.Value
Worksheets("Smart Calc").Activate
Worksheets("Smart Calc").Range("A10").Select
Do While ActiveCell.Value <> ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = test
Next
Application.DisplayAlerts = False
Application.EnableEvents = False
Worksheets("Step 1 - Manifold 8640").Activate
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub