Simple VBA Help

retractedspace

New Member
Joined
Jun 10, 2015
Messages
3
I know this will sound very simple for members but I have never used VBA.

I want a macro in my excel to when I use the shortcut CTRL + W to run a macro which does the following

Takes the cell I am in copies it
Then inserts it 5 columns to the right pushing the other columns right as it inserts
Then to delete data in the in the 5 cells to the left.. with the slected cell back where I started ready for new data

The VB needs to ignore what Row its on ie it is not always run on row 2

Going From (Blue indicates selected cell)

ABCDEFG
DateText 1Text 2Text 3Text 4Date 2{Blank}

To (Blue indicates selected cell)

ABCDEFG
{Blank}{Blank}{Blank}{Blank}{Blank}Date 1Date 2
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
You say:
Then inserts it 5 columns to the right pushing the other columns right as it inserts

If you are currently on Row 4 (for example) do you wish to truly Insert 5 Worksheet Columns, or do you wish to "move" only row 4 data 5 columns to the right? Advise.
 
Upvote 0
I have data in Columns
A, B, C, D, E, F and G

I want the data in Column A (only the cell selected not the entire column ) to be copied and the inserted into Column F the data that was in F pushed right into G (Shift:=xlToRight) as there could be a long set of data in H, I, J, K etc.

The data then in A, B, C, D and E deleted leaving the selection back on A ready for new data to be input.
 
Upvote 0
Hi.
A good way to start is to record macros and look what the recorded script looks like.

Do you mean pushing all other columns to the right? then its like this:
Sub fiveright()
'
' fiveright Macro
'
' Keyboard Shortcut: Ctrl+w
'
Range(ActiveCell.Offset(0, 1), Selection.End(xlToRight)).Select
Selection.Cut
ActiveCell.Offset(0, 5).Select
ActiveSheet.Paste
ActiveCell.Offset(0, -6).Select
Selection.Cut
ActiveCell.Offset(0, 5).Select
ActiveSheet.Paste
ActiveCell.Offset(0, -5).Select
End Sub



If you just want to push the F column to the right its like this:
Sub fiveright()
'
' fiveright Macro
'
' Keyboard Shortcut: Ctrl+w
'
Range(ActiveCell.Offset(0, 5),Selection.End(xlToRight)).Select
Selection.Cut
ActiveCell.Offset(0, 1).Select
ActiveSheet.Paste
ActiveCell.Offset(0, -6).Select
Selection.Cut
ActiveCell.Offset(0, 5).Select
ActiveSheet.Paste
Range(ActiveCell.Offset(0, -1), ActiveCell.Offset(0, -4)).Select
Selection.ClearContents
ActiveCell.Offset(0, -1).Select
End Sub

Nils
 
Upvote 0
ok I have recorded the macro, but I need it to use the row I am on not always go back to Row 4.

Sub Macro3()
'
' Macro3 Macro
'

'
Selection.Copy
Range("K4").Select
Selection.Insert Shift:=xlToRight
Range("F4:J4").Select
Range("J4").Activate
Application.CutCopyMode = False
Selection.ClearContents
Range("F4").Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,096
Messages
6,053,510
Members
444,669
Latest member
Renarian

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