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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Not sure what you're trying to achieve.

You've explained what you've got (I think), but not what you want to do with it.
 
Upvote 0
Why do you want to use VBA? You can achieve the same with excel formulas:


Excel Workbook
ABC
1numberside1side2
211*
322*
433*
544*
655*
76*10
87*9
98*8
109*7
1110*6
121111*
131212*
141313*
151414*
161515*
1716*20
1817*19
1918*18
2019*17
2120*16
Sheet1


Just copy the formulas in B2 and C2 down across your 49500 rows and you got what you want.
 
Upvote 0
This worked for me:

Code:
Sub Test()
    Dim i As Long
    For i = 1 To 49500 Step 5
        If (i - 1) Mod 10 = 0 Then
            With Cells(i, 2)
                .Value = i
                .Resize(5).DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
                    Step:=1, Stop:=i + 4, Trend:=False
            End With
        Else
            With Cells(i, 3)
                .Value = i + 4
                .Resize(5).DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
                Step:=-1, Stop:=i, Trend:=False
            End With
        End If
    Next i
End Sub
 
Upvote 0
using office 2010

sorry my bad- what you can see is what I have done by hand (1-20) - i need to expand it all the way to 49,500. It will take hours type out and i know it can be done using a loop in vba- just don't know how to achieve it (doesn't help that the text version i pasted in looks nothing like the excel version and doesn't highlight the blank cells in the columns between the sets of numbers)
does this help clarify my query?
 
Upvote 0
The two suggestions above should sort out your requirement.

As for posting worksheet extracts, next time try placing a border around the cells and selecting a small font - 8pt or 9pt.
 
Upvote 0
Just to make life difficult I've been asked to change it to the below, but this time just to 30,000.

how do i modify the script to achieve this?
Excel Workbook
JKL
1Numberside 1side 2
211
322
433
544
655
7620
8719
9818
10917
111016
12116
13127
14138
15149
161510
171615
181714
191813
201912
212011
WIP
Excel 2010
 
Upvote 0
In case the answer to my previous question is yes:

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

I have added some constants so that the code is a little more generic.
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,681
Members
452,937
Latest member
Bhg1984

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