VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,232
ANy other way to write this code..
Code:
ActiveWorkbook.Sheets("Sur").Columns("R:R").Select
Selection.Insert Shift:=xlToRight
Columns("S:S").Select
Selection.Copy
Columns("R:R").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
 
Last edited:

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Code:
Sub Test()
  With ThisWorkbook.Sheets("Sur")
    .Columns("R").Insert Shift:=xlToRight
    .Columns("S").Copy
    .Columns("R").PasteSpecial xlPasteValuesAndNumberFormats
    Application.CutCopyMode = False
  End With
End Sub
 
Upvote 0
Also:

Code:
    Columns("R:R").Select
    Selection.Copy
    Selection.Insert Shift:=xlToRight
This assumes the Sur sheet is already active.
 
Upvote 0
I think this should also work (also assuming the Sur sheet is active)...

[S:S].Insert
[R:R].Copy [S1]
 
Last edited:
Upvote 0
Wow Thanks..
For this..
Code:
Workbooks("QDC.xlsb").Activate
'ActiveWorkbook.Sheets("Sur").Columns("E:E").Select
ActiveWorkbook.Sheets("Sur").Columns("D:D").Select
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Columns("D:D").Select
Selection.Copy
Range("AK1").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Any idea pls
 
Upvote 0
Wow Thanks..
For this..
Code:
Workbooks("QDC.xlsb").Activate
'ActiveWorkbook.Sheets("Sur").Columns("E:E").Select
ActiveWorkbook.Sheets("Sur").Columns("D:D").Select
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
[B][COLOR="#FF0000"]Columns("D:D").Select
Selection.Copy[/COLOR][/B]
Range("AK1").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Any idea pls
Once you have selected Column D and shifted right twice, there is nothing in Column D to copy to Column AK. What exactly is this code supposed to be doing?
 
Upvote 0
Yes...Col D after 2 columns inserting...Col D Copy to AK to do Text to Column..
Data in Col D
Code:
6/1/2018  2:19:41 PM
Ak wil get 6/1/2018
Al wil also get 6/1/2018
Al wil get 2:19:41 PM

Copy AK and AI in Col D and E.
 
Upvote 0
Just throwing it out there, but does anyone else think it's bad practice to make assumptions about which sheet/workbook is active, and inefficient to be selecting objects (such as ranges) in order to work with them?
 
Upvote 0
Yes...Col D after 2 columns inserting...Col D Copy to AK to do Text to Column..
Data in Col D
Code:
6/1/2018  2:19:41 PM
Ak wil get 6/1/2018
Al wil also get 6/1/2018
Al wil get 2:19:41 PM

Copy AK and AI in Col D and E.
Please reread your code, especially the first active line of code (not the one you commented out which I think may be the line you actually want to be active) and then reread my comment again.
 
Upvote 0
Both salient points, @ParamRay. Perhaps the shortest way to handle the original request with your points would be to modify Rick's code as follows:

Code:
    Sheets("Sur").Columns("S").Insert
    Sheets("Sur").Columns("R").Copy Sheets("Sur").Range("S1")
My original snippet still had a Select in it. Since VBABEGINER's original code also required that the Sur sheet be selected, I didn't see a problem with my code also requiring that, but I did think it would be beneficial to explicitly comment on it. I could have spent more time finding a way to remove the Select from my code, but I had time constraints, and since my snippet was already 4 lines shorter than the original, I felt it worthwhile to post.
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,448
Members
448,966
Latest member
DannyC96

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