Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 83
Default macros vba question

is there a way that when I save as a file.

If a cell in a worksheet says Week 1 it will copy and paste with vaules a col
if if says week 2 is will copy and paste with values a different col in the
worksheet
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,069
Default macros vba question

You can do this with a macro. I am assuming you mean a particular cell on a
particular sheet, not just any cell on any sheet. The following code checks
cell A1 on Sheet1 whenever you save the workbook. If A1 contains Week 1 then
column D is copied & pasted in place as values. If A1 contains Week 2 then
column E is copied & pasted in place as values.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim txt As String
On Error Resume Next
txt = ThisWorkbook.Sheets("Sheet1").Range("A1").Value
Select Case txt
Case "Week 1"
Columns("D:D").Select
Case "Week 2"
Columns("E:E").Select
Case Else
Exit Sub
End Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End Sub

This code must be placed in the the ThisWorkbook module of your workbook.
Right-click on any sheet tab and select View Code. This opens the Visual
Basic Editor (VBE). Select View Project Explorer. You'll see a
'VBAProject' for your workbook with the sheets listed under it and something
called ThisWorkbook. Double-click on ThisWorkbook. Paste the above code in
the big empty window. Edit the sheet name, cell reference, and columns as
needed. Then select File Close to return to normal Excel.

If you are new to macros, this link to Jon Peltier's site may be helpful:
http://peltiertech.com/WordPress/200...e-elses-macro/

Hope this helps,

Hutch

" wrote:

is there a way that when I save as a file.

If a cell in a worksheet says Week 1 it will copy and paste with vaules a col
if if says week 2 is will copy and paste with values a different col in the
worksheet

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
Question on Macros Juan Carlos Excel Discussion (Misc queries) 2 September 10th 09 03:56 PM
Question on Macros in 2007 Vicky Excel Discussion (Misc queries) 4 September 5th 08 08:10 PM
Question about macros. [email protected] Excel Discussion (Misc queries) 3 May 11th 06 09:01 PM
Macros/Signatures Question Curt New Users to Excel 1 June 19th 05 12:39 AM
question macros wnl2007 Excel Worksheet Functions 1 June 10th 05 10:56 PM


All times are GMT +1. The time now is 01:13 PM.

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

About Us

"It's about Microsoft Excel"