tropics123
Board Regular
- Joined
- May 11, 2016
- Messages
- 85
I'm trying to get the macro to look for "Mary Lee" in header (row 1) and puts in the word "LOAN" below it. It should go all the way down to match the number of rows in column A. The name "Mary Lee" may appear multiple times in the header. Data will change daily, so the number of rows in Column A will change.
This is what the macro is currently doing. It stopped after finding "Mary Lee" the first time and overrode her name. Macro is at the bottom. Thanks for your help!
[TABLE="class: cms_table_grid, width: 500, align: center"]
<tbody>[TR]
[TD]Column A[/TD]
[TD]Column B
Mary LeeLOAN[/TD]
[TD]Column C
Luke Skywalker[/TD]
[TD]Column D
Mary Lee[/TD]
[TD]Column E
Bob Smith[/TD]
[TD]Column F
Mary Lee[/TD]
[TD]Column G
Joe Watson[/TD]
[/TR]
[TR]
[TD]2/5/19[/TD]
[TD]LOAN[/TD]
[TD]$90[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]$23[/TD]
[/TR]
[TR]
[TD]3/15/19[/TD]
[TD]LOAN[/TD]
[TD]$19[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]$587[/TD]
[/TR]
[TR]
[TD]5/15/19[/TD]
[TD][/TD]
[TD]$35[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]$6560[/TD]
[/TR]
</tbody>[/TABLE]
Desired result:
[TABLE="class: cms_table_grid, width: 500, align: center"]
<tbody>[TR]
[TD]Column A[/TD]
[TD]Column B
Mary Lee[/TD]
[TD]Column C
Luke Skywalker[/TD]
[TD]Column D
Mary Lee[/TD]
[TD]Column E
Bob Smith[/TD]
[TD]Column F
Mary Lee[/TD]
[TD]Column G
Joe Watson[/TD]
[/TR]
[TR]
[TD]2/5/19[/TD]
[TD]LOAN[/TD]
[TD]$90[/TD]
[TD]LOAN[/TD]
[TD][/TD]
[TD]LOAN[/TD]
[TD]$23[/TD]
[/TR]
[TR]
[TD]3/15/19[/TD]
[TD]LOAN[/TD]
[TD]$19[/TD]
[TD]LOAN[/TD]
[TD][/TD]
[TD]LOAN[/TD]
[TD]$587[/TD]
[/TR]
[TR]
[TD]5/15/19[/TD]
[TD]LOAN[/TD]
[TD]$35[/TD]
[TD]LOAN[/TD]
[TD][/TD]
[TD]LOAN[/TD]
[TD]$6560[/TD]
[/TR]
</tbody>[/TABLE]
Borrowed some of this macro idea from JoeMo
Sub AddinWordLOAN()
Sheets("Sheet3").Select
Dim tgtHdrs As Variant, Fnd As Range, fAdr As String
Dim LastRow As Long
tgtHdrs = Array("Mary Lee") 'Look for name "Mary Lee" in the header row 1 and put in the word LOAN below it
Application.ScreenUpdating = False
For i = LBound(tgtHdrs) To UBound(tgtHdrs)
Set Fnd = Rows(1).Find(what:=tgtHdrs(i), lookat:=xlWhole, MatchCase:=False)
If Not Fnd Is Nothing Then
fAdr = Fnd.Address
End If
Do
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Range(Fnd.Offset(2, 0), Cells(Rows.Count, Fnd.Column).End(xlUp)).Value = "LOAN" 'the word LOAN should go all the way down to match number of rows in column A
Set Fnd = Rows(1).FindNext(Fnd)
If Fnd Is Nothing Then Exit Do
If Fnd.Address = fAdr Then Exit Do
Loop
Next i
Application.ScreenUpdating = True
End Sub
This is what the macro is currently doing. It stopped after finding "Mary Lee" the first time and overrode her name. Macro is at the bottom. Thanks for your help!
[TABLE="class: cms_table_grid, width: 500, align: center"]
<tbody>[TR]
[TD]Column A[/TD]
[TD]Column B
Mary LeeLOAN[/TD]
[TD]Column C
Luke Skywalker[/TD]
[TD]Column D
Mary Lee[/TD]
[TD]Column E
Bob Smith[/TD]
[TD]Column F
Mary Lee[/TD]
[TD]Column G
Joe Watson[/TD]
[/TR]
[TR]
[TD]2/5/19[/TD]
[TD]LOAN[/TD]
[TD]$90[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]$23[/TD]
[/TR]
[TR]
[TD]3/15/19[/TD]
[TD]LOAN[/TD]
[TD]$19[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]$587[/TD]
[/TR]
[TR]
[TD]5/15/19[/TD]
[TD][/TD]
[TD]$35[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]$6560[/TD]
[/TR]
</tbody>[/TABLE]
Desired result:
[TABLE="class: cms_table_grid, width: 500, align: center"]
<tbody>[TR]
[TD]Column A[/TD]
[TD]Column B
Mary Lee[/TD]
[TD]Column C
Luke Skywalker[/TD]
[TD]Column D
Mary Lee[/TD]
[TD]Column E
Bob Smith[/TD]
[TD]Column F
Mary Lee[/TD]
[TD]Column G
Joe Watson[/TD]
[/TR]
[TR]
[TD]2/5/19[/TD]
[TD]LOAN[/TD]
[TD]$90[/TD]
[TD]LOAN[/TD]
[TD][/TD]
[TD]LOAN[/TD]
[TD]$23[/TD]
[/TR]
[TR]
[TD]3/15/19[/TD]
[TD]LOAN[/TD]
[TD]$19[/TD]
[TD]LOAN[/TD]
[TD][/TD]
[TD]LOAN[/TD]
[TD]$587[/TD]
[/TR]
[TR]
[TD]5/15/19[/TD]
[TD]LOAN[/TD]
[TD]$35[/TD]
[TD]LOAN[/TD]
[TD][/TD]
[TD]LOAN[/TD]
[TD]$6560[/TD]
[/TR]
</tbody>[/TABLE]
Borrowed some of this macro idea from JoeMo
Sub AddinWordLOAN()
Sheets("Sheet3").Select
Dim tgtHdrs As Variant, Fnd As Range, fAdr As String
Dim LastRow As Long
tgtHdrs = Array("Mary Lee") 'Look for name "Mary Lee" in the header row 1 and put in the word LOAN below it
Application.ScreenUpdating = False
For i = LBound(tgtHdrs) To UBound(tgtHdrs)
Set Fnd = Rows(1).Find(what:=tgtHdrs(i), lookat:=xlWhole, MatchCase:=False)
If Not Fnd Is Nothing Then
fAdr = Fnd.Address
End If
Do
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Range(Fnd.Offset(2, 0), Cells(Rows.Count, Fnd.Column).End(xlUp)).Value = "LOAN" 'the word LOAN should go all the way down to match number of rows in column A
Set Fnd = Rows(1).FindNext(Fnd)
If Fnd Is Nothing Then Exit Do
If Fnd.Address = fAdr Then Exit Do
Loop
Next i
Application.ScreenUpdating = True
End Sub
Last edited: