Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default auto add column

Hi there,

i am hoping you can help.

i hav the following code (see below) which takes numbers from multiple
spreadsheets etc (and it works well) however i am trying to do 1 last thing
and that is as follows:

The number that is placed in cell (iRow, 6) i would like to have tallied at
the end of the script, so for instance if there are 70 numbers then i would
like to leave a space and have a tally appear just underneath it in Cell 'f'
Line 72. Is this easy to do?

Thanking you in advance

Scott


Sub SubGetMyData()
Application.ScreenUpdating = False

Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objSubfolder As Scripting.Folder
Dim objFile As Scripting.File
Dim iRow As Long

iRow = 3
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("e:\scott\Sotek\Invoices\")
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=objFolder.Path & "\" & objFile.Name
With ActiveWorkbook.Worksheets(1)
.Range("A13").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 1)
.Range("A14").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 2)
.Range("A15").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 3)
.Range("F7").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 4)
.Range("F8").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 5)
ThisWorkbook.Worksheets(1).Cells(iRow, 6).Value =
..Range("f45").Value
End With
ActiveWorkbook.Close savechanges:=False
iRow = iRow + 1
End If
Next

Application.ScreenUpdating = True
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default auto add column

How about:

Option Explicit
Sub SubGetMyData()
Application.ScreenUpdating = False

Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objSubfolder As Scripting.Folder
Dim objFile As Scripting.File
Dim iRow As Long

iRow = 3
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objFolder = objFSO.getfolder("e:\scott\Sotek\Invoices\")
Set objFolder = objFSO.getfolder("C:\my documents\excel\test\")
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=objFolder.Path & "\" & objFile.Name
With ActiveWorkbook.Worksheets(1)
.Range("A13").Copy _
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 1)
.Range("A14").Copy _
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 2)
.Range("A15").Copy _
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 3)
.Range("F7").Copy _
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 4)
.Range("F8").Copy _
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 5)
ThisWorkbook.Worksheets(1).Cells(iRow, 6).Value _
= .Range("f45").Value
End With
ActiveWorkbook.Close savechanges:=False
iRow = iRow + 1
End If
Next

With ThisWorkbook.Worksheets(1)
.Cells(iRow + 1, 6).Formula _
= "=sum(" & .Range(.Cells(3, 6), _
.Cells(iRow - 1, 6)).Address(0, 0) & ")"
End With

Application.ScreenUpdating = True
End Sub

I noticed that you changed that last copy (F45) to just an assignment. Just
curious: Is there some reason you didn't adjust the others, too?

ThisWorkbook.Worksheets(1).Cells(iRow, 1).value = .range("A13").value
(and so forth)



Scott wrote:

Hi there,

i am hoping you can help.

i hav the following code (see below) which takes numbers from multiple
spreadsheets etc (and it works well) however i am trying to do 1 last thing
and that is as follows:

The number that is placed in cell (iRow, 6) i would like to have tallied at
the end of the script, so for instance if there are 70 numbers then i would
like to leave a space and have a tally appear just underneath it in Cell 'f'
Line 72. Is this easy to do?

Thanking you in advance

Scott

Sub SubGetMyData()
Application.ScreenUpdating = False

Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objSubfolder As Scripting.Folder
Dim objFile As Scripting.File
Dim iRow As Long

iRow = 3
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("e:\scott\Sotek\Invoices\")
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=objFolder.Path & "\" & objFile.Name
With ActiveWorkbook.Worksheets(1)
.Range("A13").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 1)
.Range("A14").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 2)
.Range("A15").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 3)
.Range("F7").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 4)
.Range("F8").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 5)
ThisWorkbook.Worksheets(1).Cells(iRow, 6).Value =
.Range("f45").Value
End With
ActiveWorkbook.Close savechanges:=False
iRow = iRow + 1
End If
Next

Application.ScreenUpdating = True
End Sub


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default auto add column

I'd guess that you dropped this line:

With ThisWorkbook.Worksheets(1)

But your formula looks fine to me. (Maybe even easier to understand!!!)


"Scott" wrote in message ...
Hi Dave,

tried your post but i couldn't get it work as it errored here ".Cells(3, 6)"
(invalid or unqualified reference), however i managed to bash it around to
this

ThisWorkbook.Worksheets(1).Cells(iRow + 1, 6) = "=Sum(F2:F" & (iRow - 1) &
")"

It's probably not the best coded but alas it works.
Thanks for your help it was greatly appreciated.

Regards

Scott


"Dave Peterson" wrote in message
...
How about:

Option Explicit
Sub SubGetMyData()
Application.ScreenUpdating = False

Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objSubfolder As Scripting.Folder
Dim objFile As Scripting.File
Dim iRow As Long

iRow = 3
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objFolder = objFSO.getfolder("e:\scott\Sotek\Invoices\")
Set objFolder = objFSO.getfolder("C:\my documents\excel\test\")
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=objFolder.Path & "\" & objFile.Name
With ActiveWorkbook.Worksheets(1)
.Range("A13").Copy _
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 1)
.Range("A14").Copy _
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 2)
.Range("A15").Copy _
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 3)
.Range("F7").Copy _
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 4)
.Range("F8").Copy _
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 5)
ThisWorkbook.Worksheets(1).Cells(iRow, 6).Value _
= .Range("f45").Value
End With
ActiveWorkbook.Close savechanges:=False
iRow = iRow + 1
End If
Next

With ThisWorkbook.Worksheets(1)
.Cells(iRow + 1, 6).Formula _
= "=sum(" & .Range(.Cells(3, 6), _
.Cells(iRow - 1, 6)).Address(0, 0) & ")"
End With

Application.ScreenUpdating = True
End Sub

I noticed that you changed that last copy (F45) to just an assignment.

Just
curious: Is there some reason you didn't adjust the others, too?

ThisWorkbook.Worksheets(1).Cells(iRow, 1).value = .range("A13").value
(and so forth)



Scott wrote:

Hi there,

i am hoping you can help.

i hav the following code (see below) which takes numbers from multiple
spreadsheets etc (and it works well) however i am trying to do 1 last

thing
and that is as follows:

The number that is placed in cell (iRow, 6) i would like to have tallied

at
the end of the script, so for instance if there are 70 numbers then i

would
like to leave a space and have a tally appear just underneath it in Cell

'f'
Line 72. Is this easy to do?

Thanking you in advance

Scott

Sub SubGetMyData()
Application.ScreenUpdating = False

Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objSubfolder As Scripting.Folder
Dim objFile As Scripting.File
Dim iRow As Long

iRow = 3
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("e:\scott\Sotek\Invoices\")
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=objFolder.Path & "\" & objFile.Name
With ActiveWorkbook.Worksheets(1)
.Range("A13").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 1)
.Range("A14").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 2)
.Range("A15").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 3)
.Range("F7").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 4)
.Range("F8").Copy
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 5)
ThisWorkbook.Worksheets(1).Cells(iRow, 6).Value =
.Range("f45").Value
End With
ActiveWorkbook.Close savechanges:=False
iRow = iRow + 1
End If
Next

Application.ScreenUpdating = True
End Sub


--

Dave Peterson

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
Auto fit row height for one column jolowe Excel Discussion (Misc queries) 3 September 14th 09 04:06 AM
How do I add a column of numbers (auto sum)?? tonysaw Excel Worksheet Functions 1 July 6th 09 08:52 PM
auto fit of column in EXCEL msp Excel Discussion (Misc queries) 1 March 16th 09 03:02 PM
How can I auto refresh a column that has an auto filter in place Pastal Excel Discussion (Misc queries) 1 December 18th 07 11:43 AM
Auto BOLD max value in a column gevans Excel Worksheet Functions 2 March 6th 06 08:34 PM


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