0

I need help with do until loop. In one sheet "overview", I have the formulas in certain ranges for more countries. Every country has it 3 times (costs) and every time I need to move (offset) by 9 columns to copy and paste into other sheet "Overview_values") in the same range.

Below is the code I have tried. Overview is the sheet of the formulas, in overview_v I would like to paste the same results as numbers. Num 48 means that I have 16 countries and for each country I have to do it 3 times. comp_of_costs_overview range is the starting range from overview with formulas comp_of_costs_overview_v range is the demanding range where I would like to paste as values I need to offset this by 9 columns till the last country, but when I run this code every time I fill only the range comp_of_costs_overview_v without any offset (the other countries are not filled with values).

Dim comp_of_costs_overview As Range
Dim comp_of_costs_overview_v As Range
Dim posun_stlpec As Range
Dim num As Integer
num = 48
Do
num = num - 3
Set posun_stlpec = Range("U25:U30")
Worksheets("Overview").Activate
Set comp_of_costs_overview = Range("L25:L30")
Worksheets("Overview_values").Activate
Set comp_of_costs_overview_v = Range("L25:L30")
Worksheets("Overview").Activate
comp_of_costs_overview.Select
Selection.Copy
Worksheets("Overview_values").Activate
comp_of_costs_overview_v.Select
Selection.PasteSpecial Paste:=xlPasteValues
Set posun_stlpec = Range("U25:U30")
Loop Until num = 0

I Have no error during the code, just does not work how I would like to see

mandu J.
  • 33
  • 3
  • 2
    You will benefit heavily from reading [this](https://stackoverflow.com/q/10714251/9758194) post. – JvdV Aug 22 '19 at 09:20
  • 1
    Unless the data on your worksheets is changing (getting recalculated after each copy/paste), you are performing the exact same action 16 times. Your code is not changing anything while you're running the loop. And do take a look at the link provided by @JvdV – PeterT Aug 22 '19 at 12:48
  • I agree with JvdV and PeterT. Also, you aren't using `Offset()` anywhere that I can see. If you want to offset the range you might want to try using it. – mountainclimber11 Aug 22 '19 at 14:33

0 Answers0