Excel/copy strings


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!

Your method of copying looks fine BUT if you try to do this outside of a macro you will find that (as far as I know) it's not going to work as excel isn't happy about copying and pasting non contiguous ranges.  However, you don't have to copy and paste within a macro -


is a simplistic example but would set the value of one cell to the value of another - by extension, this can work across worksheets and can use offset in the same way.
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


Aidan Heritage


I have provided first hand support since `95 for Microsoft Office majoring in Word and Excel - support for all versions from 2 onwards. I'm based in the UK, so please allow for time differences when asking me questions from other parts of the world!


My background is in the insurance industry and call centre areas, but have been called upon to provide many varied solutions.

I'm educated to UK A level standard, but as I left school some 30 years ago that is rather irrelevent - university of life has provided more of a background!

©2016 About.com. All rights reserved.