Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 386
Default Paste and cut code

Hi,

Could someone give me a code please that (in this order) in each of sheets 4
to 11:

- Copies/paste values in cols A and K
- Deletes cols S,T and U
- Saves a copy of the file, named New file to the same directory as the
source file

Is this possible?

Thanks
LiAD
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Paste and cut code

Try this on a back-up copy as it'll delete columns!

Sam

Sub test()

Dim wb As Workbook
Dim ws As Worksheet

Set wb = ActiveWorkbook

Dim i As Integer
Dim s As String

For i = 4 To 11
s = "Sheet" & i
Set ws = wb.Worksheets(s)
With ws
.Columns("A:A").Value = .Columns("A:A").Value
.Columns("K:K").Value = .Columns("K:K").Value
.Columns("S:U").Delete
End With
Next i

wb.SaveAs wb.Path & "\Newfile.xls"

End Sub


"LiAD" wrote:

Hi,

Could someone give me a code please that (in this order) in each of sheets 4
to 11:

- Copies/paste values in cols A and K
- Deletes cols S,T and U
- Saves a copy of the file, named New file to the same directory as the
source file

Is this possible?

Thanks
LiAD

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 386
Default Paste and cut code

Hi,

I get an error on

Set ws = wb.Worksheets(s)

Any ideas why?

Thanks for your help.

"Sam Wilson" wrote:

Try this on a back-up copy as it'll delete columns!

Sam

Sub test()

Dim wb As Workbook
Dim ws As Worksheet

Set wb = ActiveWorkbook

Dim i As Integer
Dim s As String

For i = 4 To 11
s = "Sheet" & i
Set ws = wb.Worksheets(s)
With ws
.Columns("A:A").Value = .Columns("A:A").Value
.Columns("K:K").Value = .Columns("K:K").Value
.Columns("S:U").Delete
End With
Next i

wb.SaveAs wb.Path & "\Newfile.xls"

End Sub


"LiAD" wrote:

Hi,

Could someone give me a code please that (in this order) in each of sheets 4
to 11:

- Copies/paste values in cols A and K
- Deletes cols S,T and U
- Saves a copy of the file, named New file to the same directory as the
source file

Is this possible?

Thanks
LiAD

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Paste and cut code

It's looking for "Sheet4" in the current workbook (assuming it fails on the
first loop) so Sheet4 may not exist.

Sam

"LiAD" wrote:

Hi,

I get an error on

Set ws = wb.Worksheets(s)

Any ideas why?

Thanks for your help.

"Sam Wilson" wrote:

Try this on a back-up copy as it'll delete columns!

Sam

Sub test()

Dim wb As Workbook
Dim ws As Worksheet

Set wb = ActiveWorkbook

Dim i As Integer
Dim s As String

For i = 4 To 11
s = "Sheet" & i
Set ws = wb.Worksheets(s)
With ws
.Columns("A:A").Value = .Columns("A:A").Value
.Columns("K:K").Value = .Columns("K:K").Value
.Columns("S:U").Delete
End With
Next i

wb.SaveAs wb.Path & "\Newfile.xls"

End Sub


"LiAD" wrote:

Hi,

Could someone give me a code please that (in this order) in each of sheets 4
to 11:

- Copies/paste values in cols A and K
- Deletes cols S,T and U
- Saves a copy of the file, named New file to the same directory as the
source file

Is this possible?

Thanks
LiAD

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 386
Default Paste and cut code

Hi,

The workbook I have has 11 sheets.
I am on sheet 2 when i try to run the macro.
Even if i change the sheet name to Sheet 4 it still doesn't work.

Is there something else in this line that trips up?

Set ws = wb.Worksheets(s)

Thanks

"Sam Wilson" wrote:

It's looking for "Sheet4" in the current workbook (assuming it fails on the
first loop) so Sheet4 may not exist.

Sam

"LiAD" wrote:

Hi,

I get an error on

Set ws = wb.Worksheets(s)

Any ideas why?

Thanks for your help.

"Sam Wilson" wrote:

Try this on a back-up copy as it'll delete columns!

Sam

Sub test()

Dim wb As Workbook
Dim ws As Worksheet

Set wb = ActiveWorkbook

Dim i As Integer
Dim s As String

For i = 4 To 11
s = "Sheet" & i
Set ws = wb.Worksheets(s)
With ws
.Columns("A:A").Value = .Columns("A:A").Value
.Columns("K:K").Value = .Columns("K:K").Value
.Columns("S:U").Delete
End With
Next i

wb.SaveAs wb.Path & "\Newfile.xls"

End Sub


"LiAD" wrote:

Hi,

Could someone give me a code please that (in this order) in each of sheets 4
to 11:

- Copies/paste values in cols A and K
- Deletes cols S,T and U
- Saves a copy of the file, named New file to the same directory as the
source file

Is this possible?

Thanks
LiAD

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA code does not copy and paste to next row for each zip code Miguel Excel Programming 5 November 14th 08 03:13 PM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
Help with my cut and paste code jln via OfficeKB.com Excel Programming 1 September 12th 06 01:23 PM
Got the Copy/Cut Code But what is the Paste Code Corey Excel Programming 7 July 7th 06 02:23 PM
Where do I paste this Code? Kevin Excel Programming 5 October 22nd 03 04:08 AM


All times are GMT +1. The time now is 05:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"