+ Reply to Thread
Results 1 to 5 of 5

Link cell from variable named sheet to cell on another sheet with variable rows

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Link cell from variable named sheet to cell on another sheet with variable rows

    Hello all. I need to link cells in a sheet with a name provided by the user "shtName", to a cell in row Q on sheet "SNSs". I have used:

    Range("Q9").Formula = "='" & shtName & "'!B60"
    to link cells that are in static rows, but in this case the rows on the SNSs sheet will be variable. The process is that when the frmScoutEntry is run, the user enters scout information and the applicable sheet and entries are made on other sheets. When the new scout name is created on the SNSs sheet, I need the cell Q9 to be linked to B60 on the newly created sheet (the name is held in the variable shtName). The next time the code is run, a new scout will be added to the SNSs sheet so the previous scout linked cell is now Q11. The value in still needs to remain linked to the previously added scout.

    I thought perhaps an IF statement in the code could match the scout names on the SNSs and scout-named sheets and link the applicable cell in Q to the scout sheet B60 but I have never been good with IF statements:

    If Sheets("SNSs").Range("A:A") = shtName.Range("$A$2" & " " & "$A$3") Then
        shtName.Range("B60")=Sheets("SNSs").Range.offset()16
    Any help would be appreciated.

    Thanks,
    Andrew
    Attached Files Attached Files
    Last edited by drewship; 12-08-2010 at 08:57 AM.

  2. #2
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Link cell from variable named sheet to cell on another sheet with variable rows

    Hello again. I have been fooling with this and the following formula placed in cell B60 of the new scout's sheet compares the combined scout name in cell B59

    =A2 & " " & B2
    with the names on the SNSs sheet and provides the value of the applicable cell in column Q.

    =VLOOKUP(B59,SNSs!A7:Q42,17,FALSE)
    Since I actually have 2 rows (Pack and Council) tied to each scout, I need to modify the formula to lookup the scout for each modifier (Pack and Council). In essence, I need to lookup the scout and the Pack and provide that value and I also need to lookup the scout and the Council and provide that value.

    Can someone help modify the formula to do this?

    Thanks,
    Andrew

  3. #3
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Link cell from variable named sheet to cell on another sheet with variable rows

    Andrew - you may not want to hear this, but I would revisit your spreadsheet layout. If you had a sheet with all your data on a row by row basis, would be much easier. I couldn't really work out what you are trying to do (could just be me though).

  4. #4
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Link cell from variable named sheet to cell on another sheet with variable rows

    Thanks for the reply StephenR. I was thinking along the same lines and did the following:

    On the SNSs sheet, I added a column B (shifted the others to the right) and use the following formula copied down:

    =A7 & " " & C7
    This combines the scout name with either Pack or Council so each row is identified seperately. After the next scout is added to the sheet the code creates a named range :

    SNSNames
    that includes all rows and columns needed for the vlookup.

    The code then selects the new scout sheet and places the vlookup formula:

    newSht.Select
        Range("B60") = "=VLOOKUP(B59,SNSNames,17,FALSE)"
        Range("B61") = "=VLOOKUP(D59,SNSNames,17,FALSE)"

    All the code runs without an error but I get a #N/A in B60 and B61 instead of 0 (since no values have yet been added to the scout's SNSs rows).

    Any idea how to correct this?

    Thanks,
    Andrew
    Attached Files Attached Files
    Last edited by drewship; 12-07-2010 at 01:21 PM. Reason: uploaded file

  5. #5
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Link cell from variable named sheet to cell on another sheet with variable rows

    Never mind...I was missing a space in my concatenation...

+ 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