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
Application.CutCopyMode = False
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.
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