VBA to set an active cell and then insert row/column and copy formats

smittymj

New Member
Joined
Jun 12, 2018
Messages
23
Good day all!

This is my first time posting and I'm glad to be here! I'm trying to make a simple excel sheet for people who aren't too familiar with Excel. I'm a total VBA newbie and I would really appreciate help in building a macro to:


  1. Find specific text in the sheet and go to that cell/set that cell as active
  2. Insert row above that cell and copy format of the row above the new row OR insert column to the left of that cell and copy formats of the column to the left of the new column

Really hoping someone can help me with this. Thank you very much!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
In the developer ribbon you can click "Record Macro." Do exactly what you just posted above and then open up the VBA screen (Alt + F11). Find the macro in the Module and you will now have the bare bones of what you need. Post that using the
Code:
[\CODE] tags and someone should be along shortly to provide better assistance.
 
Upvote 0
Hi I managed to get this to work, adding a row:

Code:
Sub ADDROW_NR()    Cells.Find(What:="NR1", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
    Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
End Sub

Adding a column is:

Code:
Sub ADDCOL()    Cells.Find(What:="ADDCOL", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
    Selection.EntireColumn.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
End Sub


Hoping this can help someone in the future! :)
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,267
Members
449,075
Latest member
staticfluids

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