LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 788
Default reutrn a value from a cell in each workbook filename from anot

i used F8, and found some strange things... first of all, i keep being asked
that the summary.xls file is already open(which is the file i opened for the
list), so what i did was put the summary.xls file into a folder, that makes
the macro unable to list that filename... then, the master file, the one
with no total value, i made into a hidden attribute.ok. after that, i tried
running F8, and it so happens that the first macro runs, but the second,
which is the one that's supposed to get the values, doesn't... so i jumped to
that line, and started the F8, and it works... so now my problem is, why
doesn't the macro run from the first code, to the second code when i open the
file?

"Joel" wrote:

the two subroutines are independant which means myDIR doesn't call Gettotal.
Get total must be run by itself. This seems to be the only logically reason
for the code not to run except if "grand total" is not on the worksheet. Any
other problem would of created an error. Do you see any workbooks openning
and closing when the code is running?

The default mode for "find" is to ignore case so this isn't the problem.
One other possiblity if there are leading or trailing blank in the cell with
"grand total". You may want to make the following change.

from:
Set c = sht.Find(what:="TOTAL", LookIn:=xlValues)
to:
Set c = sht.Find(what:="TOTAL", LookIn:=xlValues,LookAt:=xlPart)

You colud add a break point by click on the different lines in the code and
then hitting F9. You can also single step through the code by pressing F8.



"Chris" wrote:

nothing happened... i changed the code a bit though, since i was using
"total" instead of "grand total", and "sheet1" i changed to "production
cost", which is my sheet name...

nothing happened, the only comforting difference right now is that i don't
have to bother putting a "\" after the A1 cell for the first macro to run...?
my code now looks like this....

Sub myDIR()
myfolder = Range("A1").Value
RowCount = 2
First = True
Do
If First = True Then
Filename = Dir(myfolder & "\*.xls")
First = False
Else
Filename = Dir()
End If
If Filename < "" Then
Range("A" & RowCount) = Filename
RowCount = RowCount + 1
End If
Loop While Filename < ""
End Sub

Sub Gettotals()
myfolder = Range("A1").Value
With ThisWorkbook.ActiveSheet
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set FileNames = .Range("A2:A" & LastRow)
End With
For Each Cell In FileNames
Workbooks.Open Filename:=myfolder & "\" & Cell
Set sht = ActiveWorkbook.Sheets("Sheet1").Cells
Set c = sht.Find(what:="TOTAL", LookIn:=xlValues)
If Not c Is Nothing Then
total = c.Offset(rowoffset:=0, columnoffset:=1)
Cell.Offset(rowoffset:=0, columnoffset:=1) = total
End If

ActiveWorkbook.Close
Next Cell

End Sub

 
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
CELL("filename") doesn't work on shortcut workbook link? Kevin Excel Worksheet Functions 12 February 6th 10 07:33 PM
vba, get filename of this workbook md[_2_] Excel Discussion (Misc queries) 3 March 29th 08 12:04 PM
reutrn a value from a cell in each workbook filename from another Chris Excel Programming 6 November 27th 07 02:02 AM
Cell("filename") doesn't update to new filename when do save as. Louis Excel Worksheet Functions 2 March 22nd 07 07:27 PM
My workbook filename [email protected] Excel Programming 3 April 25th 05 03:55 PM


All times are GMT +1. The time now is 08:35 AM.

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"