+ Reply to Thread
Results 1 to 13 of 13

VBA get value from differnt sheets

  1. #1
    Registered User
    Join Date
    02-29-2012
    Location
    Leicester
    MS-Off Ver
    Excel 2010
    Posts
    9

    VBA get value from differnt sheets

    Hi there I am not a VBA Programmer so its all new to me
    What I am trying to do is alter an existing VBA code basically
    I got 2 sheets
    In sheet one I get the site id and now I wanted to create a function which take site id and a string Title as parameters and
    Return a cell value from sheet two how can I do this

    Eg.
    In sheet1 I should be able to call

    Name = GetName(SiteId,”SalesManager”)

    Public Function GetName ( int SiteID, string Title ) as string

    GetName = from st in Sheet2
    Where st.siteid = SiteId and st.title = Title
    Select st.fullname

    End Function
    Appreciate all your help
    Thanks

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: VBA get value from differnt sheets

    If you could provide a sample workbook showing what you want to do it would help a great deal.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    02-29-2012
    Location
    Leicester
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: VBA get value from differnt sheets

    sure
    in sheet1 i got a cell (D) and SubjectID
    and in sheet2 i got cell (A) named SiteId and cell(c)named Title and Cell(E) fullName
    so i got a button in sheet1
    the code behind the button
    i got
    Dim SiteID As String

    SiteID =Mid(Sheet1.Cells(RowNumber, Columns(i)).Text, 1, 4)
    so now what i wanted is i want a function which take
    site id and a string
    and retrun the FullName from sheet2 where it match the row of siteid and the Title
    so i can call
    like Name = GetName(SiteId,”SalesManager”)

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: VBA get value from differnt sheets

    No attachment.

    Dom

  5. #5
    Registered User
    Join Date
    02-29-2012
    Location
    Leicester
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: VBA get value from differnt sheets

    SORRY YES I HAVE CREATED A SAMPLE SHEET
    IN SHEET ONE CELL A got siteID
    so what i wanted is a fuction
    where i can pass the site id and a string
    and it should fatch the fullname from sheet to
    eg
    Name =GetName(123,"Sales Manager")
    so Name ="Tony Cookes"
    Attached Files Attached Files

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: VBA get value from differnt sheets

    Why do you need to create a vba function for this when Vlookup would do the job?

    Dom

  7. #7
    Registered User
    Join Date
    02-29-2012
    Location
    Leicester
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: VBA get value from differnt sheets

    i am editing a part to the existing vba code of a button click it create a letter using the information from this two sheets.
    all the vba codes are in sheet1 so now i wanted to get the information from sheet2

  8. #8
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: VBA get value from differnt sheets

    Maybe:

    Please Login or Register  to view this content.
    Dom

  9. #9
    Registered User
    Join Date
    02-29-2012
    Location
    Leicester
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: VBA get value from differnt sheets

    THANKS a lot mate i will post you back if worked
    thanks again

  10. #10
    Registered User
    Join Date
    02-29-2012
    Location
    Leicester
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: VBA get value from differnt sheets

    its throughing an error please help i have attached some of the screen shoots
    Attached Files Attached Files

  11. #11
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: VBA get value from differnt sheets

    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Dom
    Last edited by Domski; 02-29-2012 at 09:32 AM.

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,202

    Re: VBA get value from differnt sheets

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  13. #13
    Registered User
    Join Date
    02-29-2012
    Location
    Leicester
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: VBA get value from differnt sheets

    ya its working thanks a lot to use this function for get more information how can i change rngFindSiteIDRange.Offset(0, rngFindTitleRange.Column - 1)
    to sent a cell name so in that case
    i am passing 3 pice of information siteid,title and the name of the cell i wanted to return
    eg if i a pass
    Please Login or Register  to view this content.
    this should retrun the value of cell named("Name")
    Please Login or Register  to view this content.
    this should return the Main_Fax
    thanks a lot for your help
    Last edited by Rushdy Najath; 02-29-2012 at 10:23 AM.

+ 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.6.0 RC 1