You are here:

# Excel/macro(copying misc ranges)

Question
Sub JJ()
Dim wksFrom As Worksheet, wksTo As Worksheet
Dim copyFrom As Range, pasteTo As Range
Dim iRow As Long
Set wksFrom = ThisWorkbook.Sheets("Sheet4")
Set wksTo = ThisWorkbook.Sheets("Sheet3")
For iRow = 0 To 37
Set copyFrom = wksFrom.Range("B11:E11").Offset(iRow * 9, 0)
Set pasteTo = wksTo.Range("B5").Offset(iRow * 10, 0)       copyFrom.copy
wksTo.Paste pasteTo
Application.CutCopyMode = False
Next iRow

End Sub

This is working great. But I need help with different sets of ranges(see below)
I am trying to copy several ranges
Set copyFrom = wksFrom.Range("B11:E11, B13:E13, B7:E7").Offset(iRow * 9, 0)
(I do not know how to set several ranges in a string!)

Set pasteTo = wksTo.Range("B5,B6, B7").Offset(iRow * 10, 0)
Or loops has to be single?(one range-one copy?)

Thank you very much!
Roy

No, you cannot copy from 3 cells to one cell in that manner.   Looks like you're possibly using those "merged cells", they're of the devil!  Get thee behind me Satan.

Joking aside, you will have to use the .value method to get the value from a 3-cell-merge into a single cell.

wksTo.Range("B5").Offset(iRow*10).Value =  wksFrom.Range("B11").Value

If B11:E11 is a merged cell, the value is still stored in just B11.
Questioner's Rating
 Rating(1-10) Knowledgeability = 10 Clarity of Response = 10 Politeness = 10 Comment Thank you. But they are not merged. I am trying copy different ranges, say b7:e7, next b11:e11 and so on to different locations on the same sheet but say 37 times(so it a loop)

This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

#### Jerry Beaucaire

##### Expertise

Excel Formulas, macros, automation. Microsoft Excel MVP - 2010. Code site with free code snippets and techniques: http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/files

##### Experience

Microsoft Excel MVP - 2010. I have my own extensive Excel help/code site: http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/files ===================== I have been offering free assistance as an Excel aid on many web sites for many years: (http://www.excelforum.com - JBeaucaire) ======== (http://www.askmehelpdesk.com/spreadsheets - JBeaucaire) ======= (http://www.mrexcel.com/forum - jbeaucaire)

Education/Credentials
Bachelor's Degree from Azusa Pacific University in Mathematics and Music Composition

Awards and Honors
Microsoft Excel MVP 2010