Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default New Twist on a Previous Inquiry

On July 20th, 2005 I posted an inquiry regarding how to "Copy only Visible
Cells of a Variable Range between Worksheets" (See link)

http://www.microsoft.com/office/comm...8d3&sloc=en-us

Now I'm trying to take this concept one step further: I want to Copy only
Visible Cells of a Variable Range on a Variable Worksheet to another Workbook.

The workbooks are "Command.xls" (which contains all the code and two
worksheets; one for the user interface and a second which is our paste
target) and "Travel.xls" (which contains all the data on sheet one with a
subset of that data pasted to sheet two as described in the above link).

At the time the code executes, both workbooks are already open. I've tried
various approaches to this problem, but so far I just end up with a "Runtime
Error 91" Object or With Block not set. Any suggestions?

Damian Carrillo
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default New Twist on a Previous Inquiry

Hi Damian,

Try something like:

Dim rng As Range
Dim rng1 As Range
Dim destRng As Range
Dim destWB As Workbook
Dim srcWB As Workbook
Dim srcSh As Worksheet
Dim destSh As Worksheet


Set srcWB = Workbooks("Book1.xls") '<<======= CHANGE
Set destWB = Workbooks("Book2.xls") '<<======= CHANGE

Set srcSh = srcWB.Sheets("Sheet1") '<<======= CHANGE
Set destSh = destWB.Sheets("Sheet2") '<<======= CHANGE

Set rng = srcSh.AutoFilter.Range

Set rng1 = rng.SpecialCells(xlCellTypeVisible)

Set destRng = destSh.Range("A1")

rng1.Copy Destination:=destRng

End Sub


---
Regards,
Norman



"Damian Carrillo" wrote in
message ...
On July 20th, 2005 I posted an inquiry regarding how to "Copy only Visible
Cells of a Variable Range between Worksheets" (See link)

http://www.microsoft.com/office/comm...8d3&sloc=en-us

Now I'm trying to take this concept one step further: I want to Copy only
Visible Cells of a Variable Range on a Variable Worksheet to another
Workbook.

The workbooks are "Command.xls" (which contains all the code and two
worksheets; one for the user interface and a second which is our paste
target) and "Travel.xls" (which contains all the data on sheet one with a
subset of that data pasted to sheet two as described in the above link).

At the time the code executes, both workbooks are already open. I've
tried
various approaches to this problem, but so far I just end up with a
"Runtime
Error 91" Object or With Block not set. Any suggestions?

Damian Carrillo



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default New Twist on a Previous Inquiry

Hi Norman,

I tried to adapt this code to my project but it failed. This is part of a
larger subroutine. Here's what I came up with. Any ideas how I messed it up?

Damian

'Transfers only summary line data from Sheet1 to Sheet2
Dim SourceRange As Range
Dim SpecialRange As Range
Dim TargetRange As Range

Set SourceRange = Sheets(1).AutoFilter.Range
Set SpecialRange = SourceRange.SpecialCells(xlCellTypeVisible)
Set TargetRange = Sheets(2).Range("A1")

SpecialRange.Copy
TargetRange.PasteSpecial , Paste:=xlPasteAll
SpecialRange.Copy
TargetRange.PasteSpecial , Paste:=xlPasteValues
SelectCurrentRegion
Selection.AutoFilter

'Transfers consolidated data from Sheet2 to AirTravelBill Assistant
Dim SourceRange1 As Range
Dim SpecialRange1 As Range
Dim TargetRange1 As Range
Dim TargetWorkbook As Workbook
Dim SourceWorkbook As Workbook
Dim SourceSheet As Worksheet
Dim TargetSheet As Worksheet

Set SourceWorkbook = Workbooks("Travel.xls")
Set TargetWorkbook = Workbooks("AirTravelBill Assistant.xls")
Set SourceSheet = SourceWorkbook.Sheets(2)
Set TargetSheet = TargetWorkbook.Sheets(2)
Set SourceRange1 = SourceSheet.AutoFilter.Range
Set SpecialRange1 = SourceRange1.SpecialCells(xlCellTypeVisible)
Set TargetRange1 = TargetSheet.Range("A1")

SpecialRange1.Copy Destination:=TargetRange1

"Norman Jones" wrote:

Hi Damian,

Try something like:

Dim rng As Range
Dim rng1 As Range
Dim destRng As Range
Dim destWB As Workbook
Dim srcWB As Workbook
Dim srcSh As Worksheet
Dim destSh As Worksheet


Set srcWB = Workbooks("Book1.xls") '<<======= CHANGE
Set destWB = Workbooks("Book2.xls") '<<======= CHANGE

Set srcSh = srcWB.Sheets("Sheet1") '<<======= CHANGE
Set destSh = destWB.Sheets("Sheet2") '<<======= CHANGE

Set rng = srcSh.AutoFilter.Range

Set rng1 = rng.SpecialCells(xlCellTypeVisible)

Set destRng = destSh.Range("A1")

rng1.Copy Destination:=destRng

End Sub


---
Regards,
Norman



"Damian Carrillo" wrote in
message ...
On July 20th, 2005 I posted an inquiry regarding how to "Copy only Visible
Cells of a Variable Range between Worksheets" (See link)

http://www.microsoft.com/office/comm...8d3&sloc=en-us

Now I'm trying to take this concept one step further: I want to Copy only
Visible Cells of a Variable Range on a Variable Worksheet to another
Workbook.

The workbooks are "Command.xls" (which contains all the code and two
worksheets; one for the user interface and a second which is our paste
target) and "Travel.xls" (which contains all the data on sheet one with a
subset of that data pasted to sheet two as described in the above link).

At the time the code executes, both workbooks are already open. I've
tried
various approaches to this problem, but so far I just end up with a
"Runtime
Error 91" Object or With Block not set. Any suggestions?

Damian Carrillo




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
Product Inquiry: SpreadsheetWEB smartin Excel Discussion (Misc queries) 2 May 18th 09 11:50 PM
Chart Inquiry confused!! Excel Discussion (Misc queries) 1 October 29th 08 02:39 PM
Lookup inquiry again Lorderon Excel Discussion (Misc queries) 2 August 26th 08 11:20 PM
Formula Question - 2nd Inquiry Shu of AZ Excel Discussion (Misc queries) 6 March 31st 08 10:19 AM
Pivot Table inquiry MLLEGRIS Excel Discussion (Misc queries) 0 August 22nd 05 04:07 PM


All times are GMT +1. The time now is 11:54 PM.

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"