Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

excel vb : how to set the cell reference into a variable?

Cells.Find(What:="Add In", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _

xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _

, SearchFormat:=False).Activate

The above code tried to find a cell titled 'Add in' and from there, i want to set a variable to capture the cell reference number such as 'B4' if the string is found in that cell. How do I do that?

2 Answers

Relevance
  • Lowa
    Lv 5
    1 decade ago
    Favorite Answer

    'There may be a better way to do it, but here's my idea:

    Dim myRow, myCol as Integer

    myRow = ActiveCell.Row

    myCol = ActiveCell.Column

    'Then when you want to refer to the cell, use this:

    Cells(myRow, myCol).Activate

    'You can also do math with this, like if you want the column next to your cell:

    Cells(myRow, myCol+1).Activate

    'Or if you want the first column in the same row:

    Cells(myRow, 1).Activate

    'Hope this helps!

  • Anonymous
    5 years ago

    Well, I'm not 100% sure I understand what you're doing. It's difficult to imagine your exact spreadsheet, but I'll give it a shot. I think the quickest way to take care of that number in A2 is to just add another column with the function: =A3+$A$2 (drag this function down the whole column) Then work off the values in the new column to test how many values are in the high/low range using COUNTIF. This would make it possible for the sheet to auto-adjust if A2 was changed at some point.

Still have questions? Get your answers by asking now.