ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to set macro using cell location (https://www.excelbanter.com/excel-programming/302069-how-set-macro-using-cell-location.html)

namsilat

how to set macro using cell location
 
I have ten random values (text) in Column A from A1 to A10. On column
B, there are 10 numbers (between 1 to 10) arranged in random squence,
so B1 may be 4, B2 may be 8 and so on. On column C, I want to get the
value of the cell indicated by the NUMBER, such that if B1 is 4, then
in C1 I want to display the text from A4, if B2 is 8, I want to
display text from A8. Is it possible to set up a macro to utilize
that?

Dave Peterson[_3_]

how to set macro using cell location
 
How about a worksheet formula:

Put this in C1 and drag down:
=INDEX($A$1:$A$10,B1)



namsilat wrote:

I have ten random values (text) in Column A from A1 to A10. On column
B, there are 10 numbers (between 1 to 10) arranged in random squence,
so B1 may be 4, B2 may be 8 and so on. On column C, I want to get the
value of the cell indicated by the NUMBER, such that if B1 is 4, then
in C1 I want to display the text from A4, if B2 is 8, I want to
display text from A8. Is it possible to set up a macro to utilize
that?


--

Dave Peterson


Dave Peterson[_3_]

how to set macro using cell location
 
and if you really need a macro, here's one way:

Option Explicit
Sub testme01()

Dim myRng As Range
Dim myCell As Range
With ActiveSheet
Set myRng = .Range("c1:c10")
For Each myCell In myRng.Cells
myCell.Value = .Range("a" & myCell.Offset(0, -1).Value)
Next myCell
End With
End Sub




Dave Peterson wrote:

How about a worksheet formula:

Put this in C1 and drag down:
=INDEX($A$1:$A$10,B1)

namsilat wrote:

I have ten random values (text) in Column A from A1 to A10. On column
B, there are 10 numbers (between 1 to 10) arranged in random squence,
so B1 may be 4, B2 may be 8 and so on. On column C, I want to get the
value of the cell indicated by the NUMBER, such that if B1 is 4, then
in C1 I want to display the text from A4, if B2 is 8, I want to
display text from A8. Is it possible to set up a macro to utilize
that?


--

Dave Peterson


--

Dave Peterson



All times are GMT +1. The time now is 02:36 AM.

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