PC Review


Reply
Thread Tools Rate Thread

Copy, Paste and Print Cells from a Named Range

 
 
iperlovsky
Guest
Posts: n/a
 
      6th Aug 2008
I have the following routine to copy a cell in the named range 'One', paste
the value into cell B4 of worksheet 'Trust', print the named range 'Two' and
then repeat this procedure for all of the cells in the named range 'One'. I
don't think this makes a difference, but the named ranges are on different
sheets. I am receiving a run-time error 13 - type mismatch. Not sure, but
the values to be copied from 'One' to cell B4 are stored as text.
Is there an easy fix to my macro?

Sub printAll()
Dim i
Dim myCount
myCount = Range("One")
For i = 0 To myCount
With Range("One")
.Copy
.Worksheets("Trust").Range("B4").Value
.Range("Two").Print
End With
If i = myCount Then
End If
Next i
End Sub
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      6th Aug 2008
Your code is a long way off from what you describe. So you want to copy the
individual values in range One into a specific cell on Sheet Trust and then
print out a range from that sheet??? Assuming that to be the case this will
be a lot closer to what you have asked...

dim rng as range

for each rng in worksheets("Sheet1").Range("One")
with worksheets("Trust")
.range("B4").value = rng.value
.range("Two").PrintPreview 'Change to printout
end with
next rng
--
HTH...

Jim Thomlinson


"iperlovsky" wrote:

> I have the following routine to copy a cell in the named range 'One', paste
> the value into cell B4 of worksheet 'Trust', print the named range 'Two' and
> then repeat this procedure for all of the cells in the named range 'One'. I
> don't think this makes a difference, but the named ranges are on different
> sheets. I am receiving a run-time error 13 - type mismatch. Not sure, but
> the values to be copied from 'One' to cell B4 are stored as text.
> Is there an easy fix to my macro?
>
> Sub printAll()
> Dim i
> Dim myCount
> myCount = Range("One")
> For i = 0 To myCount
> With Range("One")
> .Copy
> .Worksheets("Trust").Range("B4").Value
> .Range("Two").Print
> End With
> If i = myCount Then
> End If
> Next i
> End Sub

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      6th Aug 2008
Maybe...

Option Explicit
Sub printAll()
Dim myCell As Range
Dim OneRng As Range

Set OneRng = ActiveWorkbook.Names("One").RefersToRange

For Each myCell In OneRng.Cells
myCell.Copy _
Destination:=Worksheets("Trust").Range("b4")
ActiveWorkbook.Names("Two").RefersToRange.PrintOut preview:=True
Next myCell

End Sub

After you get it working, delete that Preview:=true stuff.

iperlovsky wrote:
>
> I have the following routine to copy a cell in the named range 'One', paste
> the value into cell B4 of worksheet 'Trust', print the named range 'Two' and
> then repeat this procedure for all of the cells in the named range 'One'. I
> don't think this makes a difference, but the named ranges are on different
> sheets. I am receiving a run-time error 13 - type mismatch. Not sure, but
> the values to be copied from 'One' to cell B4 are stored as text.
> Is there an easy fix to my macro?
>
> Sub printAll()
> Dim i
> Dim myCount
> myCount = Range("One")
> For i = 0 To myCount
> With Range("One")
> .Copy
> .Worksheets("Trust").Range("B4").Value
> .Range("Two").Print
> End With
> If i = myCount Then
> End If
> Next i
> End Sub


--

Dave Peterson
 
Reply With Quote
 
iperlovsky
Guest
Posts: n/a
 
      6th Aug 2008
Yes, your code is correct and efficient. Thanks for the help!

"Jim Thomlinson" wrote:

> Your code is a long way off from what you describe. So you want to copy the
> individual values in range One into a specific cell on Sheet Trust and then
> print out a range from that sheet??? Assuming that to be the case this will
> be a lot closer to what you have asked...
>
> dim rng as range
>
> for each rng in worksheets("Sheet1").Range("One")
> with worksheets("Trust")
> .range("B4").value = rng.value
> .range("Two").PrintPreview 'Change to printout
> end with
> next rng
> --
> HTH...
>
> Jim Thomlinson
>
>
> "iperlovsky" wrote:
>
> > I have the following routine to copy a cell in the named range 'One', paste
> > the value into cell B4 of worksheet 'Trust', print the named range 'Two' and
> > then repeat this procedure for all of the cells in the named range 'One'. I
> > don't think this makes a difference, but the named ranges are on different
> > sheets. I am receiving a run-time error 13 - type mismatch. Not sure, but
> > the values to be copied from 'One' to cell B4 are stored as text.
> > Is there an easy fix to my macro?
> >
> > Sub printAll()
> > Dim i
> > Dim myCount
> > myCount = Range("One")
> > For i = 0 To myCount
> > With Range("One")
> > .Copy
> > .Worksheets("Trust").Range("B4").Value
> > .Range("Two").Print
> > End With
> > If i = myCount Then
> > End If
> > Next i
> > End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy named range & paste values J.W. Aldridge Microsoft Excel Programming 2 1st Mar 2010 09:59 PM
copy named range & paste J.W. Aldridge Microsoft Excel Programming 2 8th Oct 2009 04:38 PM
Copy & Paste Named Range Contents BJ Microsoft Excel Programming 8 1st Aug 2008 07:18 PM
After Copy and Paste, Add to an Existing Named Range Aria Microsoft Excel Programming 4 8th Mar 2007 12:53 AM
Copy and Paste 2 columns from a named range? Simon Lloyd Microsoft Excel Programming 2 28th May 2006 08:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:34 AM.