+ Reply to Thread
Results 1 to 8 of 8

Get current cell address

  1. #1
    Registered User
    Join Date
    12-18-2006
    Posts
    36

    Get current cell address

    What is the code to return the address of the current cell ?


    Problem:
    I am running through a loop looking for a value so I don't know what row I am on when I hit that value.
    When I hit it, I need to know the row number and how to use that number to reference another cell.


    Poor code example of what I am after:

    rowlocation = get.current.cell.row

    activate.cell("A "& rowlocation &" ")



    Thanks for any tips....
    Sorry if it is a simple question, second day of learning VB for excel...

  2. #2
    Valued Forum Contributor
    Join Date
    07-11-2004
    Posts
    851
    something like this should work for you - you need to define the range where you are searching ("myrange"

    thisitem = 'whatever you are looking for
    Set rng = Sheets("sheet1").Range("myrange").Find(thisitem)
    If rng Is Nothing Then GoTo someplace
    thisrow = rng.Row
    cells(thisrow,1).select
    someplace:
    not a professional, just trying to assist.....

  3. #3
    Registered User
    Join Date
    12-18-2006
    Posts
    36
    Hi duane thank you for the quick response...
    Being new I am still confused.

    What I am trying to do


    Delete the rows I mark.
    I am marking some cells in a column with a Y.
    Running a loop down a column until I hit a Y.
    Deleting the row.
    Then deleting the same row on sheet2.
    continuing the loop until done.


    The test code I was using:
    If IsEmpty(ActiveCell) = False Then
    Rows("21:21").Select
    Selection.ClearContents
    End If
    Sheets("Sheet2").Select
    Rows("21:21").Select
    Selection.ClearContents
    The new code I tried:

    If IsEmpty(ActiveCell) = False Then
    thisrow = rng.Row
    cells(thisrow,1).select
    Selection.ClearContents
    End If
    Sheets("Sheet2").Select
    cells(thisrow,1).select
    Selection.ClearContents


    Gave error on thisrow = rng.Row

    Any ideas ?

  4. #4
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Classic problem.

    When deleting rows, it is best to start from last row and work up. For example:


    Dim lastRow as Long

    lastRow = 'however you determine last row

    For i = lastRow to 1 Step -1
    If "however you determine to delete the row" Then
    Rows(i).Delete
    End if
    Next i

  5. #5
    Registered User
    Join Date
    12-18-2006
    Posts
    36

    Talking

    Thanks MSP77079



    Dim lastRow as Long

    lastRow = 'however you determine last row

    For i = lastRow to 1 Step -1
    If "however you determine to delete the row" Then
    Rows(i).Delete
    End if
    Next i

    Sweet...

  6. #6
    Valued Forum Contributor
    Join Date
    07-11-2004
    Posts
    851
    well it all depends how your sheet is set up. For example, if you a blank column A except for some cells in which you placed a "Y", then you could start at row 64000 and keep going end(xlup) to find the next "Y" going up toward row 1, deleting each row as you find it. if the column is not otherwise blank then you need to find the "Y"'s

    thisitem = Y
    Set rng = Sheets("sheet1").Range("myrange").Find(thisitem)
    If rng Is Nothing Then GoTo someplace 'someplace kicks you out of the 'macro
    thisrow = rng.Row
    cells(thisrow,1).entirerow.delete
    ...

    someplace:
    end sub

  7. #7
    Registered User
    Join Date
    11-03-2006
    Posts
    6
    This sample to defined cell's address:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    12-18-2006
    Posts
    36
    Hey thanks guys....

    With all your code I shouldn't have a problem now and have learned new ways of doing things.

    Thankyou all.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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