Help needed on macro for project!

Shaun_Lin

New Member
Joined
Jun 22, 2016
Messages
4
Hi,

I am trying to write a macro to assign a set new of serial number to each row. For example, each row will be given a number (in sequence) after every 8 rows and when there are no other numbers below it, the code will go back up again to continue the pattern again. Any help on this will be very much appreciated. Thank you!:LOL::LOL::LOL:


OLD
NUMBER​
NEW
SERIAL NUMBER​
1​
1​
2​
4​
3​
7​
4​
10​
5​
13​
6​
16​
7​
19​
8​
22​
9​
2​
10​
5​
11​
8​
12​
11​
13​
14​
14​
17​
15​
20​
16​
23​
17​
3​
18​
6​
19​
9​
20​
12​
21​
15​
22​
18​
23​
21​
24​
24​

<colgroup><col style="margin-left: 40px;"><col style="margin-left: 40px;"></colgroup><tbody>
</tbody>
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG22Jun29
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, num [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer,[/COLOR] c, st [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer,[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A2"), Range("a" & Rows.Count).End(xlUp))
num = Rng.Count / 8
c = 1: st = 1
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
   Dn.Offset(, 1) = c: n = n + 1
   [COLOR="Navy"]If[/COLOR] n Mod 8 = 0 [COLOR="Navy"]Then[/COLOR]
      st = st + 1: c = st
   [COLOR="Navy"]Else[/COLOR]
       c = c + num
   [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Sub macro4()

Dim lastrow1 As Long
Dim k As Long
Dim l As Long
Dim j As Long

k = 2
l = 1

With ActiveSheet
lastrow1 = .Cells(.Rows.Count, "A").End(xlUp).Row
End With

For i = 1 To lastrow1 - 1

j = k + (l - 1) * 8
If j > lastrow1 Then
k = k + 1
l = 1
j = k + (l - 1) * 8
End If

Cells(j, 2).Value = i
l = l + 1
Next
Cells(1, 2).Value = "New Series"
End Sub
 
Upvote 0
Dear MickG and bhos123,

Thanks for the prompt reply and help! The solutions work fine and I was able to solve the problem with that. :)
 
Upvote 0

Forum statistics

Threads
1,215,948
Messages
6,127,871
Members
449,410
Latest member
adunn_23

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