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
Document ID
xxxxxx
xxxxxxService:
xxxxxxLocation:
xxxxxxRegiment:
xxxxxxFunction:
xxxxxxCompany:
xxxxxxRank:
xxxxxxEnrolled:
xxxxxxDate:
xxxxxxEnlisted:
xxxxxxDate:
xxxxxxDetail:
xxxxxxCaptured:
xxxxxxPrisoner:
xxxxxxDied:
xxxxxxCause:
xxxxxxBuried:
mmmm
mmmmService:
mmmmLocation:
mmmmRegiment:
mmmmFunction:
mmmmCompany:
mmmmRank:
mmmmEnrolled:
mmmmDate:
mmmmEnlisted:
mmmmDate:
mmmmDetail:
mmmmCaptured:
mmmmPrisoner:
mmmmExchanged:
mmmmLocation:
mmmmBattle:
mmmmDate:
mmmmDetail:
mmmmLocation:
mmmmDate:
mmmmCaptured:
mmmmForwarded:
mmmmDate:
mmmmDate:
mmmmLocation
mmmmDied:
mmmmCause:
mmmmBuried:

<tbody>
[TD="align: center"]1[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=D9D9D9]#D9D9D9[/URL] , align: center"]Person_ID[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=D9D9D9]#D9D9D9[/URL] "]Name[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=D9D9D9]#D9D9D9[/URL] "]Details[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=D9D9D9]#D9D9D9[/URL] "]Notes[/TD]

[TD="align: center"]2[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]4[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]5[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]7[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]9[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]10[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]11[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]12[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]13[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]14[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]15[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]16[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]17[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]19[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]20[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]21[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]22[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]23[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]24[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]25[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]26[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]27[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]28[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]29[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]30[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]31[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]32[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]33[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]34[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]35[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]36[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]37[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]38[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]39[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]40[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]41[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]42[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]43[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]44[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]45[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]46[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]47[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

</tbody>
Sheet1

 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
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

Forum statistics

Threads
1,224,823
Messages
6,181,180
Members
453,021
Latest member
Justyna P

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