+ Reply to Thread
Results 1 to 4 of 4

Cells function within a range

Hybrid View

  1. #1
    Registered User
    Join Date
    09-08-2009
    Location
    Glasgow
    MS-Off Ver
    Excel 2003 SP3
    Posts
    45

    Cells function within a range

    Hi there,

    I am currently pulling my hair out over what I thought was a simple piece of code.

    Basically I want to access a cell value using the range function. However, I need to access the row and columbn seperately as I am wanting to use activecell.row on the row and then just hardcode in the column.

    The line Im using is below but doesnt seem to be giving me bak the answer I want, any idea's?

    MsgBox (wsCD.Range((Cells(ActiveCell.Row, 5))).Value)
    wsCD is my sheet I'm working on.

    Cheers,

    Jag

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Cells function within a range

    Perhaps

    MsgBox wsCD.Cells(ActiveCell.Row,5).Value

  3. #3
    Registered User
    Join Date
    09-08-2009
    Location
    Glasgow
    MS-Off Ver
    Excel 2003 SP3
    Posts
    45

    Re: Cells function within a range

    Thanks for the reply, but it still doesnt seem to work for the purposes I need it.

    Howcome when I use it within the following method, it doesnt return a value when I call msgbox?

    Public Sub example1()
    Dim wsCD As Worksheet, wsNew As Worksheet
    Dim HL As Hyperlink
    Dim rngCopy As Range, HLrange As Range
    On Error GoTo ExitPoint
    Application.ScreenUpdating = False
    Set wsCD = Sheets("Compartment Details")
    Set wsNew = Sheets.Add(After:=Sheets(Sheets.Count))
    For Each HL In wsCD.Hyperlinks
        HLrange = HL.Range
        MsgBox (HLrange.Value) 'tried using the function here to display the hyperlink cell value
        wsCD.Activate: HL.Follow
        Set rngCopy = ActiveCell.Offset(, 1 - ActiveCell.Column).Resize(, 20)
        wsNew.Cells(wsNew.Rows.Count, "A").End(xlUp).Offset(1).Resize(, 20).Value = rngCopy.Value
        Set rngCopy = Nothing
    Next HL
    ExitPoint:
    Set wsCD = Nothing
    Set wsNew = Nothing
    Application.ScreenUpdating = True
    End Sub
    Cheers,

    Jag

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Cells function within a range

    You must Set the range object (and good idea to release thereafter)

    Set HLRange = HL.Range
    MsgBox HLRange.Value
    Set HLRange = Nothing
    That said the above could potentially generate a LOT of dialogs... if it's more for testing perhaps use Debug over MsgBox, ie:

    Debug.Print HLRange.Address & ":" & HLRange.Value
    and use Immediate window in VBE to see the output(s)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1