VBA Copy and Transpose to merged cells

Melimob

Active Member
Joined
Oct 16, 2011
Messages
395
Office Version
  1. 365
Hi

This code is working but only copying 2 rows down instead of grabbing all till last data row?

I think it's to do with the offset or the columns /rows set but don't know how to solve?

Code:
Sub TransposeToMergedCells()
Dim StartCell As Range
Dim DestCell As Range


Set StartCell = Worksheets("HRG Clients ").Range("c3") 'Source sheet
Set DestCell = Worksheets("COD Mapping").Range("d1:az1") 'Destination sheet


For c = 1 To 1
For r = 1 To 25
DestCell.Offset(0, r - 1) = StartCell.Offset(r - 1, c - 1)
Next
Set DestCell = DestCell.Offset(1, 0)
Next
End Sub

Many thanks
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
this is driving me crazy ;(

My source data is starting from C3 down:
abc1
abc2
abc3
abc4
abc5
abc6

The destination is starting in D1 across but needs to placed in d1, f1, h1 etc since they are merged cells.
Running my code it's showing:

abc1 abc2 abc4 abc6

It does the first 2 correctly but abc3 and abc5 is missing?

Code:
Sub TransposeToMergedCells()
Dim StartCell As Range
Dim DestCell As Range




Set StartCell = Worksheets("HRG Clients ").Range("c3") 'Source sheet
Set DestCell = Worksheets("COD Mapping").Range("d1") 'Destination sheet




For c = 1 To 1
For r = 1 To 20
DestCell.Offset(0, r - 1) = StartCell.Offset(r - 1, c - 1)
Next
Set DestCell = DestCell.Offset(0, 1)
Next
End Sub



I know this has got to be something simple but can't figure it?

many thanks
 
Upvote 0

Forum statistics

Threads
1,216,473
Messages
6,130,838
Members
449,597
Latest member
buikhanhsang

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top