Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to sum value from master worksheet taking value from other close worksheet


Dear all...

Please help. I'm really seek for an advice.

I'm having consolidate button in my main worksheet and if clik on it,
it will sum all the value in each cell that is taken from different
excel file. Which I don't specify the name of the file. My problem are
:
1) if my value has refrence example: in C7 my sum value is 300
my C9 is having =ROUND(C7/7*12,2). my sum value instead of taking the
sum value it become REF. Return Error 2023

2) I think my style is not efficient enough so any suggestion? The
point I have to read from close file is because user doesn't want to
see all the worksheet.

Sub Consolidate1()

Dim SheetName As Worksheet
Dim emptyRows As Long

On Error Resume Next

ReadDataFromAllWorkbooksInFolder

MsgBox "Process completed.", vbInformation + vbOKOnly
End Sub

__________________________________________________

Sub ReadDataFromAllWorkbooksInFolder()

Dim FolderName As String, exName As String, r As Long, cValue As
Variant
Dim exList() As String, FileCnt As Integer, fcnt As Integer
Dim jRow As Long, RowCnt As Integer, updValue As Variant
Dim Lr As Long 'Last Row

FolderName = "C:\budget\sabah" ' create list of workbooks in
foldername

FileCnt = 0
exName = Dir(FolderName & "\" & "*.xls")
While exName < ""
FileCnt = FileCnt + 1
ReDim Preserve exList(1 To FileCnt)
exList(FileCnt) = exName
exName = Dir
Wend
If FileCnt = 0 Then Exit Sub ' get values from each workbook


For fcnt = 1 To FileCnt

For jRow = 7 To 34 'for jRow =3 t0 RowCnt

cValue = GetInfoFromClosedFile(FolderName, exList(fcnt),
"Sheet1", "C" & jRow)

If fcnt = 1 Then
Cells(jRow, 3).Formula = cValue
End If

If fcnt 1 Then
updValue = Sheets("Sheet1").Range("C" & jRow).Value
updValue = updValue + cValue
Cells(jRow, 3).Formula = updValue
End If

Next jRow
''
Next fcnt


End Sub

__________________________________________________ _

Private Function GetInfoFromClosedFile(ByVal exPath As String, _
exName As String, wsName As String, cellRef As String) As Variant

Dim arg As String
GetInfoFromClosedFile = ""
If Right(exPath, 1) < "\" Then exPath = exPath & "\"
If Dir(exPath & "\" & exName) = "" Then Exit Function
arg = "'" & exPath & "[" & exName & "]" & _
wsName & "'!" & Range(cellRef).Address(True, True, xlR1C1)
On Error Resume Next
GetInfoFromClosedFile = ExecuteExcel4Macro(arg)


End Function

I'm having problem in arg, return Error 2023


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to sum value from master worksheet taking value from other close worksheet

Error 2023 is a #Ref error. You need to examine the string you build for
arg and make sure it represents a valid reference.

--
Regards,
Tom Ogilvy

"nuha1578" wrote in message
...

Dear all...

Please help. I'm really seek for an advice.

I'm having consolidate button in my main worksheet and if clik on it,
it will sum all the value in each cell that is taken from different
excel file. Which I don't specify the name of the file. My problem are
:
1) if my value has refrence example: in C7 my sum value is 300
my C9 is having =ROUND(C7/7*12,2). my sum value instead of taking the
sum value it become REF. Return Error 2023

2) I think my style is not efficient enough so any suggestion? The
point I have to read from close file is because user doesn't want to
see all the worksheet.

Sub Consolidate1()

Dim SheetName As Worksheet
Dim emptyRows As Long

On Error Resume Next

ReadDataFromAllWorkbooksInFolder

MsgBox "Process completed.", vbInformation + vbOKOnly
End Sub

__________________________________________________

Sub ReadDataFromAllWorkbooksInFolder()

Dim FolderName As String, exName As String, r As Long, cValue As
Variant
Dim exList() As String, FileCnt As Integer, fcnt As Integer
Dim jRow As Long, RowCnt As Integer, updValue As Variant
Dim Lr As Long 'Last Row

FolderName = "C:\budget\sabah" ' create list of workbooks in
foldername

FileCnt = 0
exName = Dir(FolderName & "\" & "*.xls")
While exName < ""
FileCnt = FileCnt + 1
ReDim Preserve exList(1 To FileCnt)
exList(FileCnt) = exName
exName = Dir
Wend
If FileCnt = 0 Then Exit Sub ' get values from each workbook


For fcnt = 1 To FileCnt

For jRow = 7 To 34 'for jRow =3 t0 RowCnt

cValue = GetInfoFromClosedFile(FolderName, exList(fcnt),
"Sheet1", "C" & jRow)

If fcnt = 1 Then
Cells(jRow, 3).Formula = cValue
End If

If fcnt 1 Then
updValue = Sheets("Sheet1").Range("C" & jRow).Value
updValue = updValue + cValue
Cells(jRow, 3).Formula = updValue
End If

Next jRow
''
Next fcnt


End Sub

__________________________________________________ _

Private Function GetInfoFromClosedFile(ByVal exPath As String, _
exName As String, wsName As String, cellRef As String) As Variant

Dim arg As String
GetInfoFromClosedFile = ""
If Right(exPath, 1) < "\" Then exPath = exPath & "\"
If Dir(exPath & "\" & exName) = "" Then Exit Function
arg = "'" & exPath & "[" & exName & "]" & _
wsName & "'!" & Range(cellRef).Address(True, True, xlR1C1)
On Error Resume Next
GetInfoFromClosedFile = ExecuteExcel4Macro(arg)


End Function

I'm having problem in arg, return Error 2023


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/



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
automatically appending newly added data on worksheet to a master list worksheet tabylee via OfficeKB.com Links and Linking in Excel 0 December 17th 09 04:24 PM
Create new workbook and new worksheet and close. Worksheet not sav Patrick Djo Excel Worksheet Functions 0 July 20th 09 07:10 PM
Sorting Master Worksheet to Regional Worksheet teapot10 Excel Worksheet Functions 3 April 14th 08 07:08 PM
taking certian data from worksheet one to worksheet 2 [email protected] Excel Worksheet Functions 1 September 12th 06 09:01 AM
Dates period from master worksheet to another worksheet colin Excel Discussion (Misc queries) 1 April 2nd 06 03:24 AM


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