LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Copy from fixed range does not work

Joel:

After trial and erro, yes I am able to add watch and try to see, the content
of the cells I mentioned in the range, in fact in the watch window says the
value is " expression not defined in context", as a result no contents of the
rage copied to the new sheet.

Do you know what it means?

Frank

"joel" wrote:

Frank: It is hard to find this problem just looking at the code. I can't
tell what you are referding to as the FIXED RANGE. The code is dependant on
the data in the worksheet and the problem may be related to the data on the
worksheet. I recommend that you put a break point on this line and then step
through the code

If Not sourceRange Is Nothing Then

Click on line with mouse and then Press F9 to add break point. Then step
through the code by pressing F8. You can see the value of the variables by
hoving the mouse over the variables and add a Watch point by highlighting the
variable and right click mouse (select ADD WATCH).

Let me know when you better define where the error is occuring.

"Frank Situmorang" wrote:

Hello,

I am already tired, I checked and tried to follow all Codes as suggested on
Ron De Bruins's website. Filepath and the fille name have succecefully
copied, but the fixed range that I mensioned in the code is NOT copied.

I am not too good in the VBA, I appreciate if anyone can help me. The
following is the VBA:
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long

Sub ChDirNet(szPath As String)
SetCurrentDirectoryA szPath
End Sub
Sub MergeSpecificWorkbooks()
Dim MyPath As String
Dim SourceRcount As Long, FNum As Long
Dim mybook As Workbook, BaseWks As Worksheet
Dim sourceRange As Range, destrange As Range
Dim rnum As Long, CalcMode As Long
Dim SaveDriveDir As String
Dim FName As Variant


' Set application properties.
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With

SaveDriveDir = CurDir
' Change this to the path\folder location of the files.
ChDirNet "\\Admin-hdd\budget-contr\BUDGET CONTROL M\BUDGET 2009"

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xl*),
*.xl*", _
MultiSelect:=True)
If IsArray(FName) Then

' Add a new workbook with one sheet.
Set BaseWks = Workbooks.Add(xlWBATWorksheet).Worksheets(1)
rnum = 2


' Loop through all files in the myFiles array.
For FNum = LBound(FName) To UBound(FName)
Set mybook = Nothing
On Error Resume Next
Set mybook = Workbooks.Open(MyPath & FName(FNum), _
Password:="KIKI", WriteResPassword:="KIKI", UpdateLinks:=0)

On Error GoTo 0

If Not mybook Is Nothing Then

On Error Resume Next
With mybook.Worksheets("SUMMARY")
Set sourceRange =
.Range("C7,C8,E7,D118,H5,D63,E63,D70,F70," & _
"D80,F80,D102,F102,D108,D109")
End With

If Err.Number 0 Then
Err.Clear
Set sourceRange = Nothing
Else
' If the source range uses all columns then
' skip this file.
If sourceRange.Columns.Count = BaseWks.Columns.Count Then
Set sourceRange = Nothing
End If
End If
On Error GoTo 0

If Not sourceRange Is Nothing Then

SourceRcount = sourceRange.Rows.Count

If rnum + SourceRcount = BaseWks.Rows.Count Then
MsgBox "There are not enough rows in the target
worksheet."
BaseWks.Columns.AutoFit
mybook.Close savechanges:=False
GoTo ExitTheSub
Else

' Copy the file name in column A.

With sourceRange
BaseWks.Cells(rnum, "A"). _
Resize(.Rows.Count).Value = FName(FNum)
End With

' Set the destination range.
Set destrange = BaseWks.Range("B" & rnum)

' Copy the values from the source range

' to the destination range.
With sourceRange
Set destrange = destrange. _
Resize(.Rows.Count,
.Columns.Count)
End With
destrange.Value = sourceRange.Value
rnum = rnum + SourceRcount
End If
End If
mybook.Close savechanges:=False
End If

Next FNum
BaseWks.Columns.AutoFit
End If

ExitTheSub:
' Restore the application properties.
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalcMode
End With
ChDirNet SaveDriveDir
End Sub

Thanks a lot in advance

Frank



 
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
Copy a Range of Data to another Work Sheet Theo Degr[_2_] Excel Programming 13 June 19th 07 12:59 PM
Copy fixed range of multiple sheets into new workbook A. Karatas Excel Programming 9 June 12th 07 08:52 AM
how to copy formulas from one range to another range in other work Miri Excel Programming 1 June 6th 07 03:52 PM
Copy a named range from an installed add-in while in anothter work Chip Pearson Excel Programming 0 January 5th 07 10:58 PM
Copy a named range from an installed add-in while in anothter work Dave Peterson Excel Programming 0 January 5th 07 10:52 PM


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