+ Reply to Thread
Results 1 to 4 of 4

Set cell value by using .Offset and .Find

Hybrid View

  1. #1
    Registered User
    Join Date
    05-22-2012
    Location
    IL
    MS-Off Ver
    Excel 2010
    Posts
    50

    Set cell value by using .Offset and .Find

    I am trying to set a cell value = to "X" by finding one cell value (= to value in cell D7 on sheet1) on another sheet (= to value in cell B7 on sheet1) and entering the "X" two columns to the left of the found value. I am using the code below. Can anyone advise what I am doing wrong here?

    Thanks

    Mike

       Dim rng2 As Range
            Set rng2 = Sheets(Sheet1.Range("B7").Value).Range("C:C").Find(Range("D8").Value, , xlValues, xlWhole)
            rng2.Offset(-2, 0).Value = "X"

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Set cell value by using .Offset and .Find

    try the following macro:
    Public Sub test()
    Dim rng2 As Range
    Sheets("Sheet2").Select
    With Range("C2", Cells(Rows.Count, 3).End(xlUp))
      Set rng2 = .Find(Sheets("Sheet1").Range("D7"), , xlValues, xlWhole)
    End With
    If Not rng2 Is Nothing Then
      rng2.Offset(0, -2).Value = "X"
    End If
    End Sub
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Registered User
    Join Date
    05-22-2012
    Location
    IL
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Set cell value by using .Offset and .Find

    Many thanks Pierre. Unfortunately I am still not getting the desired result. The Macro is running with no error message, just not making the change...
    Here is what I am using
    Dim rng2 As Range
    
    Sheets(Sheet1.Range("B7").Value).Select
    With Range("C2", Cells(Rows.Count, 3).End(xlUp))
      Set rng2 = .Find(Sheet1.Range("D7"), , xlValues, xlWhole)
    End With
    If Not rng2 Is Nothing Then
      rng2.Offset(0, -2).Value = "X"
    End If

  4. #4
    Registered User
    Join Date
    05-22-2012
    Location
    IL
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Set cell value by using .Offset and .Find

    I stand corrected...this works beautifully! Thanks Pierre!

+ 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