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: 1
Default Set cell formulas in another workbook.

I have written a macro in excel that opens a text file, deletes a load of
lines and then does text to columns, and deletes a load of rubbish I don't
need.

What I now have is data in columns a thru c and i need to set formulas for
columns d, e and f (possibly more)

The macro sits in one excel file and then open the file in a new workbook.
I need to reference the new workbook and set these required formulas for
columns d, e etc. How do i do this? The only reference i have to the
workbook is the variable myfile but this includes the full file path to the
workbook not just its name.

Anyway the code is below. Can anyone help?

Sub Macro3()

' Declare Variables
Dim a As Integer
Dim myfile As Variant

' Open Dialog box to choose file

myfile = Application.GetOpenFilename("Report Files (*.rpt), *.rpt")

If myfile = False Then Exit Sub

' Open file selected in dialog box

Workbooks.OpenText FileName:=myfile, Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, _
Tab:=False, Semicolon:=False, Comma:=False, Space:=False, _
Other:=False, FieldInfo:=Array(1, 1)

' Delete rubbish not required until end of file

a = 1
While Cells(a + 1, 1) < ""
Rows(a).EntireRow.Delete
Rows(a).EntireRow.Delete
Rows(a).EntireRow.Delete
Rows(a).EntireRow.Delete
a = a + 1
Wend

' Do text to columns

Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited,
_
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True,
_
Semicolon:=False, Comma:=True, Space:=True, Other:=False,
FieldInfo:= _
Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5,
1), Array(6, 1), Array(7 _
, 1), Array(8, 1))

' Delete unwanted columns

Columns("H:H").Delete
Columns("F:F").Delete
Columns("D:D").Delete
Columns("B:B").Delete
Columns("A:A").Delete

' Set formulas for cells in new worksheet.


End Sub





--
Chris Lewis

 
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
linked workbook cell returns 0 is source workbook cell is blank? Syd[_2_] Excel Worksheet Functions 4 April 13th 09 07:49 PM
Formulas in my Workbook Spiky Excel Worksheet Functions 0 May 19th 08 06:37 PM
COpy formulas from one workbook to another workbook Jeff Excel Discussion (Misc queries) 2 February 12th 08 02:02 PM
Tracing cell formulas to other spreadsheets on the same workbook John Smith[_2_] Excel Discussion (Misc queries) 1 December 10th 07 03:21 PM
Copying Formulas from Workbook to Workbook Rupert[_2_] Excel Discussion (Misc queries) 3 June 4th 07 03:44 PM


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