:doh:Gotta activate the sheet before you select the range.
Code:With wb1
With .Sheets(Nome)
.Paste
.Activate
.Range("A1").Select
End With
End With
Printable View
:doh:Gotta activate the sheet before you select the range.
Code:With wb1
With .Sheets(Nome)
.Paste
.Activate
.Range("A1").Select
End With
End With
Gee, what a goofed:bug: :omg2: .
Now that code is working great, but when the code comes to this line:
Code:wb2.Close savechanges:=False
the system simply hangs. I just need to close the wb2. What I am doing wrong now?:banghead:
Not sure, but I always just leech off the native syntax ..
Does it make a difference?Code:wb2.Close False
Okay, that's strange... I don't see anything wrong with that line...
Well this is my whole logic if it helps:
Code:Dim wb1 As Workbook, wb2 As Workbook
Set wb1 = ActiveWorkbook
Workbooks.Open Filename:=Arq
Set wb2 = ActiveWorkbook
With wb2
With .Sheets("CN")
.AutoFilterMode = False
.Range("D2").Select
.Cells.RemoveSubtotal
.Cells.Copy
End With
End With
With wb1
With .Sheets(Nome)
.Paste
.Activate
' Seleciona a c?lula A1
.Range("A1").Select
End With
End With
wb2.Close savechanges:=False ' System hangs here
Range("A1").Select
ActiveSheet.Select
Sheets(Nome).Name = "Standard"
Testing Zacks advice.
Sorry Zack, hanged the same way.
I'm wondering if we can't boil that code down to something like this ...
Code:Dim wb1 As Workbook, wb2 As Workbook
Set wb1 = ActiveWorkbook
Set wb2 = Workbooks.Open(Arq)
With wb2.Sheets("CN")
.AutoFilterMode = False
.Range("D2").Select
.Cells.RemoveSubtotal
.Cells.Copy wb1.Sheets(Nome).Range("A1")
End With
wb2.Close False
Range("A1").Select
Sheets(Nome).Name = "Standard"
And do you even need the line:
It doesn't seem to serve much purpose to me.Code:.Range("D2").Select
Hi guys,
Zack: Great, thanks for the Sub diet. It worked great till the end. No more problems.
Ken: You right, I have removed it.
I am marking it solved now, thank you very much Ken and Zack!:bow: :bow: :bow: :bow:
Carlos, does that mean it doesn't hang anymore?Quote:
Originally Posted by Paleo
Yes, exactly. Worked just fine. No more hanging.
Ah, excellent!
Which all goes to prove three points:
1) Using option explicit removes one potential source for errors
2) Declaring your variables properly removes another potential source for errors
3) Removing all unnecessary code and cutting it down to the bare essentials then removes all other potential sources of errors (and makes it MUCH easier to read the underlying logic)
Good work you guys! :thumb
Glad it works for you Carlos! :yes
John: Thanks buddy!! :)
Ken: Always a pleasure working with ya! ;)
John, agreed! Nice recap! :yes
It's been a fun one!
Many thanks to you all guys!! I was stuck what that and now its solved!! Thanks!!!
:beerchug: