Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Newbie question!


Hi people at Excel forum

I have just begun using VBA for Excel, so I am a newbie :) I hop
somebody can help me with the following problem:

Each of the cells from A1 until A10 contains different kind of text.
Cell B1 contains an integer between 1 and 10.
In cell B2 I want the same text as in the cell, which is pointed out b
the integer value in cell B1. For example: If B1 contains the intege
value 5, then B2 should automatically obtain the text from cell A5.

What VBA code is appropriate for cell B2?

Best regards,

Eri

--
Vestergaar
-----------------------------------------------------------------------
Vestergaard's Profile: http://www.excelforum.com/member.php...nfo&userid=795
View this thread: http://www.excelforum.com/showthread.php?threadid=48849

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Newbie question!

This best way IMHO is to use a worksheet function instead of VBA. Place the
following in cell B2:

=INDIRECT("A" & B1)

If you want to use VBA then I would suggest pasting this to the worksheet's
code module:

Private Sub Worksheet_Change(ByVal Target As Range)
Range("B2").Value = Range("A" & Range("B1").Value)
End Sub

Note that worksheet functions execute faster than VBA and so IMHO should be
used preferentially. There are of course plenty of situations where this is
not feasible.

Regards,
Greg


"Vestergaard" wrote:


Hi people at Excel forum

I have just begun using VBA for Excel, so I am a newbie :) I hope
somebody can help me with the following problem:

Each of the cells from A1 until A10 contains different kind of text.
Cell B1 contains an integer between 1 and 10.
In cell B2 I want the same text as in the cell, which is pointed out by
the integer value in cell B1. For example: If B1 contains the integer
value 5, then B2 should automatically obtain the text from cell A5.

What VBA code is appropriate for cell B2?

Best regards,

Erik


--
Vestergaard
------------------------------------------------------------------------
Vestergaard's Profile: http://www.excelforum.com/member.php...fo&userid=7955
View this thread: http://www.excelforum.com/showthread...hreadid=488493


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 180
Default Newbie question!

In B2: =INDEX(A1:A10,B1)


"Vestergaard" wrote:


Hi people at Excel forum

I have just begun using VBA for Excel, so I am a newbie :) I hope
somebody can help me with the following problem:

Each of the cells from A1 until A10 contains different kind of text.
Cell B1 contains an integer between 1 and 10.
In cell B2 I want the same text as in the cell, which is pointed out by
the integer value in cell B1. For example: If B1 contains the integer
value 5, then B2 should automatically obtain the text from cell A5.

What VBA code is appropriate for cell B2?

Best regards,

Erik


--
Vestergaard
------------------------------------------------------------------------
Vestergaard's Profile: http://www.excelforum.com/member.php...fo&userid=7955
View this thread: http://www.excelforum.com/showthread...hreadid=488493


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Newbie question!

If you want to dabble...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Address = "$B$1" Then
If IsNumeric(Target.Value) Then
Range("B2").Value = Cells(Target.Value, 1)
Range("B2").Font.Color = RGB(0, 0, 0)
Range("B2").Font.Bold = False
Else
Range("B2").Value = "Error"
Range("B2").Font.Color = RGB(255, 0, 0)
Range("B2").Font.Bold = True
End If
End If
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Newbie question!


That made the trick. Thanks to all of you!!!

Erik:)


--
Vestergaard
------------------------------------------------------------------------
Vestergaard's Profile: http://www.excelforum.com/member.php...fo&userid=7955
View this thread: http://www.excelforum.com/showthread...hreadid=488493



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
Real Newbie newbie question Dave New Users to Excel 0 January 10th 07 07:55 PM
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
Newbie With A Question Michael Excel Worksheet Functions 0 July 28th 05 11:50 PM
Newbie question EdL Excel Programming 2 August 15th 04 10:52 PM
Newbie Question .. what's this stevem[_6_] Excel Programming 2 April 2nd 04 05:06 AM


All times are GMT +1. The time now is 03:41 AM.

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"