vba looping problem

woods2007

Board Regular
Joined
Aug 29, 2007
Messages
57
Can anyone help with the below problem?

I have three columns. col 'number' runs to 49,500

side 1 has numbers 1-5 followed by 5 blank cells followed by 11-15 looping through to 49,500

side 2 has the first 5 cells blank followed by numbers 10-6 desc followed by 5 blanks followed 20-16 looping through to 49,500.



Number side1 side2
1 1
2 2
3 3
4 4
5 5
6 10
7 9
8 8
9 7
10 6
11 11
12 12
13 13
14 14
15 15
16 20
17 19
18 18
19 17
20 16

I think a loop will do it but not sure how to go about it can anyone advise?

many thanks
 
Sadly not. L7 should be 20. I have tried to show the pattern bellow, it needs to continue till it reaches 30,000. I hope it is clear. I'll be happy when I have this resolved!!!
Excel Workbook
JKL
211
322
433
544
655
7620
8719
9818
10917
111016
12116
13127
14138
15149
161510
171615
181714
191813
201912
212011
222121
232222
242323
252424
262525
272640
282739
292838
302937
313036
WIP
Excel 2010
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try:

Code:
Sub Test()
    Const Last As Long = 30000
    Const Skip As Long = 5
    Dim Toggle1 As Boolean
    Dim Toggle2 As Boolean
    Dim i As Long
    Toggle1 = True
    Toggle2 = True
    For i = 1 To Last Step Skip
        If (i - 1) Mod (Skip * 2) = 0 Then
            With Cells(i, 2)
                If Toggle1 = True Then
                    .Value = i
                    .Resize(5).DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
                        Step:=1, Stop:=i + Skip - 1, Trend:=False
                    Toggle1 = False
                Else
                    .Value = i - Skip
                    .Resize(5).DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
                        Step:=1, Stop:=i - 1, Trend:=False
                    Toggle1 = True
                End If
            End With
        Else
            With Cells(i, 3)
                If Toggle2 = True Then
                    .Value = i - 1 + (Skip * 3)
                    .Resize(5).DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
                        Step:=-1, Stop:=i - Skip + (Skip * 3), Trend:=False
                    Toggle2 = False
                Else
                    .Value = i - 1
                    .Resize(5).DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
                        Step:=-1, Stop:=i - Skip, Trend:=False
                    Toggle2 = True
                End If
            End With
        End If
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,703
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top