Trying Post Document

gzell

New Member
Joined
Apr 20, 2019
Messages
37
I am researching my Great Great Grandfathers time during the Civil War. What started to be a simple Excel file has grown to a large file, 25000+ rows. Not what I planned for but the further I got in the research the more I expanded to included all members of his units. I am new to VBA and have am trying to learn the basics to complete this document. If this request is not allowed please let me know.

Flow
Search Column D for Cell "Rank:"
When found, insert row below this Cell
Also, insert text "Age:" in column D in new row
Insert row below Cell with "Age"
insert "Residence:" in column D of this row
Loop through Range of Spreadsheet
Repeat
Until end of document
End

This is a code I found online, to enter one line but it does not work as expected. Any help would be greatly appreciated.

Sub Insert_Row_Below_Blank()
Dim i As Range
Dim cell As Range

Set i = Range("D1:D25391")
For Each cell In i.Cells
If cell.Value = "Rank:" Then
cell.Offset(1).EntireRow.Insert

End If

Next
End Sub







Excel 2016 (Windows) 32 bit
ABCDE
1Document IDPerson_IDNameDetailsNotes
2xxxxxx
3xxxxxxService:
4xxxxxxLocation:
5xxxxxxRegiment:
6xxxxxxFunction:
7xxxxxxCompany:
8xxxxxxRank:
9xxxxxxEnrolled:
10xxxxxxDate:
11xxxxxxEnlisted:
12xxxxxxDate:
13xxxxxxDetail:
14xxxxxxCaptured:
15xxxxxxPrisoner:
16xxxxxxDied:
17xxxxxxCause:
18xxxxxxBuried:
19mmmm
20mmmmService:
21mmmmLocation:
22mmmmRegiment:
23mmmmFunction:
24mmmmCompany:
25mmmmRank:
26mmmmEnrolled:
27mmmmDate:
28mmmmEnlisted:
29mmmmDate:
30mmmmDetail:
31mmmmCaptured:
32mmmmPrisoner:
33mmmmExchanged:
34mmmmLocation:
35mmmmBattle:
36mmmmDate:
37mmmmDetail:
38mmmmLocation:
39mmmmDate:
40mmmmCaptured:
41mmmmForwarded:
42mmmmDate:
43mmmmDate:
44mmmmLocation
45mmmmDied:
46mmmmCause:
47mmmmBuried:

<tbody>
</tbody>
Sheet1

 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
If you step through the code using F8, hover your mouse over lr once you get to the line after lr=, and tell us what it returns.
Also at rows 96 / 97 do you have merged cells
 
Upvote 0
In the Rows with Rank: they would also have the Rank designation of the Soldier. I removed the designation at the bottom of sheet and it worked on that entry. I do not want you to spend a lot of your time on this. I really appreciate the help. There are 3000+ entries for Rank so I might just replace the entries to Rank: and correct after we get this working. Is there a notation in the command that would tell it to look for just Rank: in the row? If not I can make this work. Thanks again for the response.
 
Upvote 0
What are the ranks that it ignores?
 
Upvote 0
It ignores ranks with any text the space after the : I changed the all the entries to Rank: and it worked. This is all done on a test worksheet. The code Fluff posted worked up to the point when it added row and text on row 96 & 97 and then it went to end. It started from top instead of bottom, as he mentioned in his last post.
 
Upvote 0
If you step through the code using F8 & stop when the row in red is highlighted yellow
Code:
Sub gzell()
   Dim Ar As Areas
   Dim Rng As Range
   With Range("D2", Range("D" & Rows.Count).End(xlUp))
      .Replace "Rank:", "=xxxRank", xlPart, , False, , False, False
      [COLOR=#ff0000]Set Ar = .SpecialCells(xlFormulas, xlErrors).Areas[/COLOR]
      .Replace "=xxxRank", "Rank:", xlPart, , False, , False, False
   End With
   For Each Rng In Ar
      Rng.Offset(1).EntireRow.Resize(2).Insert
      Rng.Offset(1).Resize(2).Value = Application.Transpose(Array("Age:", "Residence:"))
   Next Rng
End Sub

You should see cells with #NAME? in them. Do you also see cells with Rank: as well?
 
Last edited:
Upvote 0
I see #Name in the first 5 rank cells. When I click on the #Name ---=xxxRank Private. shows in the far left of the cell. The code stops at same place it did before. When I step through the remainder of the code the Rank field is replaced with the correct information. This continues to the same rank cell as before and then goes to End Sub.
 
Last edited:
Upvote 0
When you step through the code to the point that the cells show #NAME?
Are there any cells that still show Rank: rather the the name error?
 
Last edited:
Upvote 0
Rank: is in all cells below the last successful change. It is the same location it stopped previously. When stepping through the code, when it makes that change, it jumps to End Sub.
 
Upvote 0
What else is in those cells?
 
Upvote 0

Forum statistics

Threads
1,216,811
Messages
6,132,836
Members
449,761
Latest member
AUSSW

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