Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Set cell formulas in another workbook.

Sub Macro3()

' Declare Variables
Dim a As Integer
Dim myfile As Variant
Dim bk as Workbook

' 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)

Set bk = ActiveWorkbook

' 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.

MsgBox bk.name

' so use bk.name in building your formulas.

End Sub
"Chris Lewis" <no spam thanks wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default Set cell formulas in another workbook.

sub quiktest()
Dim r As Long ' -- you used a for the row
r = 3 'simulate row processing at row 3

Cells(r, 4).Formula = "=" & Cells(r, 2).Address(0, 0) & " + " & Cells(r, 3).Address(0, 0)
End Sub


--
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Chris Lewis" <no spam thanks wrote in message ...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Set cell formulas in another workbook.

hi,
WorkBook.add with create a new workbook
what are the formulas?
-----Original Message-----
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

.

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
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 03:51 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"