+ Reply to Thread
Results 1 to 10 of 10

Thread: Find method to read reference or change reference to value.

  1. #1
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,275

    Thumbs up Find method to read reference or change reference to value.

    I have two sets of code

    For Each d In Range("Prov1")
    d.Select
    ActiveCell.Offset(2, 0).Select
    ActiveCell.FormulaR1C1 = "=Cansim!R[-1]C"
    ActiveCell.Offset(14, 0).Select
    ActiveCell.FormulaR1C1 = "=Cansim!R[-14]C"
    ActiveCell.Offset(14, 0).Select
    ActiveCell.FormulaR1C1 = "=Cansim!R[-27]C"
    ActiveCell.Offset(14, 0).Select
    ActiveCell.FormulaR1C1 = "=Cansim!R[-40]C"
    ActiveCell.Offset(14, 0).Select
    ActiveCell.FormulaR1C1 = "=Cansim!R[-53]C"
    Next d
    As you can see, this sets my desired active cells to be the same as the values from sheet “Cansim”. This works great!

    This code however, does not:

    For Each c In Range("WPGCansim")
    c.Select
    Application.Worksheets("Insert").Select
    Set r = Worksheets("Insert").Range("CansimSourceNo").Find(c)
    If Not r Is Nothing Then r.Select
    This code is trying to find the proper identifier but it cannot. I’ve figured out it is because the identifier to be found is a reference to a value, not the value itself. Is there a way to have the .Find method see the value of the cells instead of the reference?

    Sorry if this makes no sense but me brain is all tricksee because of dealing with would-be car thieves last night and I’m downright tired. If needed I can upload the workbook.

    Thanks
    Last edited by Mordred; 08-13-2010 at 03:44 PM.
    Please leave a message after the beep!

  2. #2
    Valued Forum Contributor
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    1,957

    Re: Find method to read reference or change reference to value.

    Well c.value will return the value of the top left-most cell in any range, but it's the default return if you don't specify a range property anyway. So, for example, Msgbox c, will return the value of c.

    Perhaps you should tell us what problem you're experiencing with this code. Other than the fact you've got two .select statements in there that aren't needed I can't see any immediate issues with it.

  3. #3
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,275

    Re: Find method to read reference or change reference to value.

    The first code snippet retrieves all of the identifiers and places them properly into the Insert sheet (which is the data that comes from our source). I've done this because our data sheets use identifiers to fill in the data values from the source and the source does not supply the identifiers on their data tables.
    The second code is from a sub that finds the identifiers from the Insert sheet based on the identifiers from our data sheet so that it can copy the data from the insert and paste it into our data sheets.

    The problem is, the second snippet of code does not find the values in each cell in the Insert sheet. The first identifier it should find looks like this on the sheet: v735047. But, it is actually a reference that reads: =Cansim!L3. I think it is because it is a reference and not and actual value that the second code won't read it. Am I making sense or do you want to see the workbook?
    Please leave a message after the beep!

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    MSO2007 on WinXP/MSO2000 on Win7/winXP
    Posts
    2,180

    Re: Find method to read reference or change reference to value.

    I don't quite understand your explanation so I'm wondering why you are putting a formula into the cells instead of the actual value:

        For Each d In Range("Prov1")
            d.Offset(2, 0).Value = Sheets("Cansim").Cells(d.Row - 1).Value
    etc
    ??
    ---
    Ben Van Johnson

  5. #5
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,275

    Re: Find method to read reference or change reference to value.

    I've uploaded the workbook so you can get a visual of what I am doing.
    Attached Files Attached Files
    Please leave a message after the beep!

  6. #6
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,275

    Re: Find method to read reference or change reference to value.

    Now that you mention it proton, maybe that is what I will do. I'll just copy each identifier over instead. I'll give it a go and let you know how it.....goes?!
    Please leave a message after the beep!

  7. #7
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,275

    Re: Find method to read reference or change reference to value.

    I don't know and I don't think I am apt to understand today. I don't really want to copy each and every cell and then paste it into the Insert sheet because it appears like it will take far too much coding.
    Please leave a message after the beep!

  8. #8
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,275

    Re: Find method to read reference or change reference to value.

    I tried your code proton and it copies blank values based on the same row criteria as: R[-1]C
    Please leave a message after the beep!

  9. #9
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Find method to read reference or change reference to value.

    You need to search the values not the formulas:
    
    Set r = Worksheets("Insert").Range("CansimSourceNo").Find(what:=c, LookIn:=xlValues)

  10. #10
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,275

    Re: Find method to read reference or change reference to value.

    That did it romperstomper. Thank you so much.
    Please leave a message after the beep!

+ 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.2.0