LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default How Do you Change the text/value of Range in a Function?

Is it possible to change the values of a range within a function? For example:

This Works...

Sub MyFunction()
Dim i As Integer
Dim rng1 As Range
Dim rng2 As Range
Set rng1 = Range("A1:A5")
Set rng2 = Range("G1:G5")
rng1.Select
rng2.Select
rng2.Clear

For i = rng1.Row To rng1.Rows.Count
rng2.Cells(i, 1) = rng1.Cells(i, 1)
rng2.Cells(i, 2) = rng1.Cells(i, 2)
Next
End Sub

But this doesn't...
Function MyFunction()
Dim i As Integer
Dim rng1 As Range
Dim rng2 As Range
Set rng1 = Range("A1:A5")
Set rng2 = Range("G1:G5")
rng1.Select
rng2.Select
rng2.Clear

For i = rng1.Row To rng1.Rows.Count
rng2.Cells(i, 1) = rng1.Cells(i, 1)
rng2.Cells(i, 2) = rng1.Cells(i, 2)
Next
End Function

The function will have an error at the statement:
rng2.Cells(i, 1) = rng1.Cells(i, 1)

Can someone show me how to accomplish this?

TIA
 
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
Can Text Function change output text color? epiekarc Excel Discussion (Misc queries) 1 December 31st 08 02:58 AM
Change text colour if range of values all zero Robin Excel Worksheet Functions 5 August 3rd 07 02:38 PM
Using text for the range in AVERAGE function [email protected] Excel Worksheet Functions 4 July 8th 06 12:00 PM
Is there a function to change a number to text? psdunlavy Excel Worksheet Functions 3 June 12th 05 08:13 AM
Function to change text to formula Michael Beckinsale Excel Programming 1 August 27th 03 02:16 PM


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