You are here:

Excel/macro(copying misc ranges)


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)
Please help to define the ranges-I cannot find anything in internet. Is this possible at all?
Or loops has to be single?(one range-one copy?)

Thank you very much!

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.  
About Excel
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


All Answers

Answers by Expert:

Ask Experts


Jerry Beaucaire


Excel Formulas, macros, automation. Microsoft Excel MVP - 2010. Code site with free code snippets and techniques:


Microsoft Excel MVP - 2010. I have my own extensive Excel help/code site: ===================== I have been offering free assistance as an Excel aid on many web sites for many years: ( - JBeaucaire) ======== ( - JBeaucaire) ======= ( - jbeaucaire)

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

Awards and Honors
Microsoft Excel MVP 2010

©2017 All rights reserved.