Insert number to group of cells based on empty cell

gzell

New Member
Joined
Apr 20, 2019
Messages
37
I have a large spread sheet that I would like to insert number to a group of cells (Column B) based on empty cell in column E. At next empty cell add 1 to number and insert in cells in column B and loop until end of worksheet. The spreadsheet is a research document and has 27K+ rows. This will allow me to know the exact number of people in the document. Any help would be greatly appreciated.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You could give an example of how your data is and how you want the result.
 
Upvote 0
ABCDE
1Row_IDPerson_IDNameResearch Data
211Able, Ezekiel
321Able, Ezekiel1_1Army: Confederacy
431Able, Ezekiel1_2Location: Texas
541Able, Ezekiel1_3Regiment: 10th Regiment, Texas Infantry (Nelson's)
651Able, Ezekiel1_4Function: Infantry
761Able, Ezekiel1_5Company: C
871Able, Ezekiel1_6Rank: Private
981Able, Ezekiel1_7Age: Unknown
1091Able, Ezekiel1_8Residence: Unknown
11101Able, Ezekiel1_9Enrolled: Enrolled: Buchanan, Texas
12111Able, Ezekiel1_10Date: October 16, 1861
13121Able, Ezekiel1_11Enlisted: Houston, Texas
14131Able, Ezekiel1_12Date: October 25, 1861
15141Able, EzekielDetail: Hospital Nurse
16151Able, EzekielDate: November 8, 1862
17161Able, EzekielRelieved of Duty: Nurse
18171Able, EzekielDate: February 4, 1862
19181Able, EzekielCaptured: Battle of Arkansas Post
20191Able, EzekielDate: January 11, 1863
21201Able, EzekielForwarded: St. Louis, Missouri via Boats
22211Able, EzekielForwarded: Camp Douglas, Illinois via Rail
23221Able, EzekielPrisoner: Camp Douglas, Illinois
24231Able, EzekielDied: March 7, 1863
25241Able, EzekielCause: Small Pox
26262Adams, John H.
27272Adams, John H.1_1Army: Confederacy
28282Adams, John H.1_2Location: Texas
29292Adams, John H.1_3Regiment: 10th Regiment, Texas Infantry (Nelson's)
30302Adams, John H.1_4Function: Infantry
31312Adams, John H.1_5Company: I
32322Adams, John H.1_6Rank: Corporal
33332Adams, John H.1_7Age: 42
34342Adams, John H.1_8Residence: Parker County, Texas
35352Adams, John H.1_9Enlisted: Kimball, Texas or Millican, Texas
36362Adams, John H.1_10Date: January 16, 1862
37372Adams, John H.Captured: Battle Arkansas Post, Arkansas
38382Adams, John H.Date: January 11, 1863
39392Adams, John H.Forward: St. Louis, Missouri via Boats
40402Adams, John H.Forward: Camp Douglas, Illinois via Rail
41412Adams, John H.Prisoner: Camp Douglas, Illinois
42422Adams, John H.Forwarded for Exchanged_1: City Point, Virginia
43432Adams, John H.Date: April 10, 1863
44442Adams, John H.Hospital: Sick
45452Adams, John H.Location: Kingston, Georgia
46462Adams, John H.Date: March 22, 1864
47472Adams, John H.Captured: Franklin, Tennessee
48482Adams, John H.Date: November 30, 1864
49492Adams, John H.Forwarded: Nashville, Tennessee
50502Adams, John H.Forwarded: Louisville, Kentucky
51512Adams, John H.Arrived_LOUISVILLE: December 3, 1864
52522Adams, John H.Forwarded: Camp Douglas, Illinois
53532Adams, John H.Date: December 3, 1863
54542Adams, John H.Arrived: December 6, 1863
55552Adams, John H.Oath of Alegiance: June 18, 1865
56563Adams, Peter L.
57573Adams, Peter L.1_1Army: Confederacy
58583Adams, Peter L.1_2Location: Texas
59593Adams, Peter L.1_3Regiment: 10th Regiment, Texas Infantry (Nelson's)
60603Adams, Peter L.1_4Company: D
61613Adams, Peter L.1_5Function: Infantry
62623Adams, Peter L.1_6Rank: Private
63633Adams, Peter L.1_7Age: --
64643Adams, Peter L.1_8Residence: --
65653Adams, Peter L.1_9Enrolled: Fairfield, Freestone County, Texas
66663Adams, Peter L.1_10Date: October 26, 1861
67673Adams, Peter L.1_11Enlisted: Hempstead, Texas
68683Adams, Peter L.1_12Date: October 31, 1863
69693Adams, Peter L.Absent_1: January 1862-April 1864

<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Master

Worksheet Formulas
CellFormula
A1Row_ID
B1Person_ID
C1Name
D1
E1Research Data

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>


Here it is.
 
Upvote 0
How about
Code:
Sub gzell()
   Dim Rng As Range
   Dim i As Long
   For Each Rng In Range("E2:E" & Rows.Count).SpecialCells(xlConstants).Areas
      i = i + 1
      Rng.Offset(-1, -3).Resize(Rng.Count + 1).Value = i
   Next Rng
End Sub
 
Upvote 0
How about without loop

At least on my computer the test with 90,000 records, is 4 seconds faster than the Fluff macro.

Code:
Sub DAMmacro4()
  Range("B2").Value = 1
  With Range("B3:B" & Range("E" & Rows.Count).End(xlUp).Row)
    .FormulaR1C1 = "=IF(RC[3]<>"""",R[-1]C,R[-1]C+1)"
    .Value = .Value
  End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,387
Messages
6,124,633
Members
449,177
Latest member
Sousanna Aristiadou

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