Insert row above True Returned

DebbieCox

New Member
Joined
Nov 27, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I'm new to this in Excel but was very familiar with Macros making my life so easy with Lotus 123!!! Thanks in advance for helping me make the transition!

I need to insert a row with the value "ENDTRNS" above the row with TRNS

Currently
TRNS
SPL
SPL
TRNS

to be

TRNS
SPL
SPL
ENDTRNS
TRNS
 

Attachments

  • Macro help.png
    Macro help.png
    10.9 KB · Views: 2

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Such code shall do the job:
VBA Code:
Sub test()
Dim lr As Long, i As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
For i = lr To 2 Step -1
  If Cells(i, "A") = "TRNS" Then
    Rows(i).Insert
    Cells(i, "A") = "ENDTRNS"
  End If
Next i
End Sub

If there is a lot of TRNS occurences it will not be quick, so other approach shall be adopted. But may be this is good enough. Of course use your column name - I assumed it is A.
 
Upvote 0
Based on your post why would it not be
ENDTRNS
TRNS
SPL
SPL
ENDTRNS
TRNS
?
 
Upvote 0
I expect these are "enclosing" texts start transaction, some actions , end transaction, start next transaction, again some actions, end transaction, end so on.
So first row transaction shall remain in starting row,

that's why I proposed:
.
VBA Code:
For i = lr To 2 Step -1
not
VBA Code:
For i = lr To 1 Step -1

But of course I may be wrong, so let's wait for Debbie's comment
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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