ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro that uses a value as the range (https://www.excelbanter.com/excel-programming/415298-macro-uses-value-range.html)

jpbat1591

Macro that uses a value as the range
 
Hi,

I am wondering if anyone could shed some light on how i can program a value
say in A1 that is constantly changing, and use the value as the destination
to paste information on another sheet.

JLGWhiz

Macro that uses a value as the range
 
This sets c as the object variable for a value in sheet 2 that equals the
value in A1 of sheet 1. It then copies someRange designated by the user to a
destination that is two cells to the right of the cell with the found value
of c.

Sub findValueA1()
Dim c As Range
Set someRange = Sheets(1).Range("C5") '<<<Change to need
Set c = Sheets(2).Cells.Find(Sheets(1).Range("A1").Value _
LookIn:=xlValues) '<<<add additional parameters in needed.
If Not c Is Nothing Then
Sheets(1).Range(someRange).Copy Sheets(2) _
c.Offset(0, 2)
End If
End Sub




"jpbat1591" wrote:

Hi,

I am wondering if anyone could shed some light on how i can program a value
say in A1 that is constantly changing, and use the value as the destination
to paste information on another sheet.


Gary''s Student

Macro that uses a value as the range
 
Say we want to put a message in Sheet2
Sheet1, cell A1 contains Z100 (the destination address)
Sheet2, cell A2 contains the message:

"Klaatu barada nikto"


Here is a sample macro:

Sub gort()
Set a1 = Range("A1")
Set a2 = Range("A2")
destin = a1.Value
a2.Copy Sheets("Sheet2").Range(destin)
End Sub


--
Gary''s Student - gsnu200798


"jpbat1591" wrote:

Hi,

I am wondering if anyone could shed some light on how i can program a value
say in A1 that is constantly changing, and use the value as the destination
to paste information on another sheet.



All times are GMT +1. The time now is 01:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com