Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Can you please let me know how I can
1- insert a new row let say 3 exactly after Existing row 2
2- Copy Strings from 1 to 2
3- and finally delete 1
The reason that i have to do this is I have some Drop-down, look ups(which I do not know what they call in excel) in row 1 and i can not load the file like this into GIS software so I need to get rid of that, however I still need to keep the Title headers for further referencing.
thanks
Update
Sub inserter()
' inserter Macro
Rows("3:3").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Rows("2:2").Select
Selection.Copy
Rows("3:3").Select
ActiveSheet.Paste
Rows("2:2").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
End Sub
It follows what you had in point 2 and it not as per what you recorded.
Macro recorder gives all kinds of extra code. The code that you gave can be written as
Private Sub Sample()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
.Rows(3).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
.Rows(1).Copy .Rows(2)
.Rows(1).Delete Shift:=xlUp
End With
End Sub
You might also want to see THIS
but better learn to save macros. I mean I dont have in my head this code, everytime I need some code I just save it, btw avoid .select, do something like this instead:
Rows("3:3").Delete Shift:=xlUp
Hope it helps
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.