LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default How to using Address in selected Range

First off, the Range wouldn't be replacing the Offset property, it would be
replacing the c.Offest reference (assuming the "c" from your For..Each
loop). Now, assuming the "c" from your For..Each loop is being used to
establish the row number, I think you **think** you are looking for this...

Range("B" & c.Row).Value

or, alternately, like this...

Cells(c.Row, "B").Value

HOWEVER, doing this may (more than likely if your are not careful) end up
referencing the wrong worksheet. The "c" in your For..Each loop
automatically references the specified range on the worksheet you specified
for it in the Set statement... on the other hand, the above alternates, as
constructed, will reference the indicated cell on the ActiveSheet... the
Range or Cells calls have no way of knowing you want to reference a
different worksheet unless you tell it that. So, in your given For..Each
loop, you would have to do what you ask this way...

k1 = c.Value + "|" & Sheets(SchShtName).Range("B" & c.Row).Value

or, alternately, like this...

k1 = c.Value + "|" & Sheets(SchShtName).Cells(c.Row, "B").Value

And, you would have to have the Sheet reference attached to the Range call
each time you used it. Personally, I would continue using Offset myself.

--
Rick (MVP - Excel)



"moonhk" wrote in message
...
Hi All

In below part of VBA, I am using offset to build k1 value. How to
using range("B" & row_value) replace offset (0,1) ?

Dim rngToSearch As Range, rngToCheck As Range
Dim SchShtRange As String
Dim SchShtName As String
Dim k1 As String

SchShtRange = "A1:A5"

SchShtName = "RangeA"

Set rngToSearch = Sheets(SchShtName).Range(SchShtRange) 'change to
suit

For Each c In rngToSearch
If c.Value < "" Then
k1 = c.Value + "|" & c.Offset(0,1).Value
...




 
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
Address of selected range vandenberg p Excel Programming 9 July 13th 08 09:41 PM
Lower right cell address in a selected range - Excel 2007 MSweetG222 Excel Programming 10 March 25th 08 04:43 PM
Get selected cell name/address David494 Excel Programming 5 August 1st 05 03:21 PM
How do I convert a selected Cell address in a Range to Values? MichaelC Excel Programming 2 June 10th 05 01:44 PM
How do you get a Selected Range address into a variable? Jack Excel Programming 5 November 20th 03 04:09 AM


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