To Readers -
We solved Jeff's problem offline, but I'm posting solutions here for
readers. Although the readers won't have the benefit of Jeff's probelmatic
workbook, the thread should clearly describe the common problem of trying to
paste into merged cells.
Two solutions follow. The first pastes columns if the destinations are
predetermined to be single columns, but programmatically assigns values to
columns that contain merged cells (columns 3, 7, and 9 in Jeff's example).
The second solution uses programmatic assignments for all of the data.
Readers should note that either solution involves programmatically assigning
values into the left-most cell of a group of merged cells. For example, if
columns 3, 4, and 5 of row 2 are merged, you can assign a value to cell(2,3)
just as if it were not merged and the value will be visible in the merged
cells. Programmatically assigning a value to any of the other cells in the
merged group does not result in an error, but the value is not visible and
all cells in the group remain empty.
Solution I:
Sub JeffW_02()
Application.ScreenUpdating = False
For Each col In ActiveSheet.UsedRange.Columns
dC = Choose(col.Column, 1, 2, 3, 6, 7, 9) 'dC = destination Column(number)
col.Copy
If dC <> 3 And dC <> 7 And dC <> 9 Then 'if destination isn't merged,Paste
Worksheets("Tool_List").Cells(11, dC).PasteSpecial
Paste:=xlPasteValues
Else 'if destination contains merged cells, assign values cell-by-cell
Set cel = col.Cells(1, 1)
Do Until cel.Value = ""
Worksheets("Tool_List").Cells(cel.Row + 10, dC).Value = cel.Value
Set cel = cel.Offset(1, 0)
Loop
End If
Next 'col
'Wrap procedure, register cursor at A1 of Tool_List
Application.CutCopyMode = False
Worksheets("Tool_List").Activate
Range("A1").Select
End Sub
Solution II:
Sub copy_su_modified()
'Logic flow similar to Jeff's original version (cell by cell copying), but
'uses programmatic setting of cell values instead of copying.
'In the destination worksheet, the following columns are merged:
'3,4,and 5
'7 and 8
'9, 10, 11, and 12
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Tool_List")
Application.ScreenUpdating = False
iterations = ws1.Range("A1").CurrentRegion.Rows.Count
'COPY THE TOOL NUMBER
For i = 1 To iterations
ws2.Cells(i + 10, 1) = ws1.Cells(i, 1)
Next i
'COPY THE TOOL diameter
For i = 1 To iterations
ws2.Cells(i + 10, 2) = ws1.Cells(i, 2)
Next i
'COPY THE TOOL description
For i = 1 To iterations
ws2.Cells(i + 10, 3) = ws1.Cells(i, 3)
Next i
'--------------------------------------------------------
'COPY THE flute length
For i = 1 To iterations
ws2.Cells(i + 10, 6) = ws1.Cells(i, 4)
Next i
'COPY THE LFH
For i = 1 To iterations
ws2.Cells(i + 10, 7) = ws1.Cells(i, 5)
Next i
'COPY THE notes
For i = 1 To iterations
ws2.Cells(i + 10, 9) = ws1.Cells(i, 6)
Next i
'Wrap procedure, register cursor at A1
Sheets("Sheet1").Select
Range("A1").Select
Sheets("Tool_List").Select
Range("A1").Select
End Sub