LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default How to streamline this macro

Hello everybody,

This is my macro.

Dim strNameSheet As String
Dim boolFound As Boolean
Dim MySheets As Worksheet


boolFound = False
strNameSheet = "Råbalance"
For Each MySheets In Worksheets
If MySheets.Name = strNameSheet Then boolFound = True
Next
If boolFound Then
MsgBox ("This sheet already exists")
Else
Sheets.Add
ActiveSheet.Name = strNameSheet
End If



Sheets("Råbalance").Select
Cells.Select
Application.CutCopyMode = False
Selection.ClearContents
Range("A1").Select
Workbooks.Open Filename:="J:\1900 overførsler\1901_SPX_right.xls"
Cells.Select
Selection.Copy
Windows("Afd 12. World Hedged 30.06.2007.xls").Activate
Sheets("Råbalance").Select
Range("A1").Select
ActiveSheet.Paste
Cells.Select
Cells.EntireColumn.AutoFit
Columns("C:C").Select
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("C1"),
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False,
FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Selection.NumberFormat = "0"
Windows("1901_SPX_right.xls").Activate
ActiveWorkbook.Close
Range("A1").Select
End Sub


I use this template in many sheets so I was wondering if there was a
way I could avoid changing the file name everytime in this line:

Windows("Afd 12. World Hedged 30.06.2007.xls").Activate

Can´t I just make a reference to the file I am currently in or
something?

When recorded I change activation between two sheets and that is why I
have to change the name of the file everytime I make a copy of my
sheet.

any thoughts?

best regards
Heine

 
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
big list. Need advice for a new user of how to streamline it Kent New Users to Excel 2 April 1st 08 09:23 PM
How to streamline this Formula? Kuda Excel Discussion (Misc queries) 1 February 7th 06 03:05 PM
streamline SUMPRODUCT gpie Excel Worksheet Functions 4 September 23rd 05 06:05 PM
Streamline copying and pasting code Art Excel Programming 2 May 22nd 04 09:31 PM
Streamline macro code. Pete Excel Programming 1 April 21st 04 02:22 PM


All times are GMT +1. The time now is 10:14 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"