+ Reply to Thread
Results 1 to 10 of 10

VBA with sum and vlook up

  1. #1
    Registered User
    Join Date
    10-23-2014
    Location
    Liverpool
    MS-Off Ver
    2010
    Posts
    12

    Lightbulb VBA with sum and vlook up

    Sheet 1

    A1 has a name (Bob)
    A2 has a value (10)

    Button 1


    Sheet 2

    John 0
    Dave 0
    Ben 0
    Bob 0

    I need it so when someone clicks button 1 its added the value of cell a2 in sheet 1 to the next collum to the right of the name in collum a1 in sheet 1.

    example if they clicked now sheet 2 would then look liek this:-

    John 0
    Dave 0
    Ben 0
    Bob 10

    clicked it again BOB would go to 20 and so on

    I got to this but now getting an error:-

    Private Sub CommandButton1_Click()

    Please Login or Register  to view this content.
    End Sub
    Last edited by powelly04; 03-13-2015 at 02:22 PM. Reason: Rules - sorry :(

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: VBA with sum and vlook up

    Please do use code tags as required by our rules http://www.excelforum.com/forum-rule...rum-rules.html it really makes easier to read code.

    As for the problem - vlookup returns value, while you need the reference to cell to manipulate it's contents
    Best Regards,

    Kaper

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: VBA with sum and vlook up

    if your data layout is name in sheet2, cell E11, time in sheet2 cell G8 and names in Time column A (starting row 2) and total times in Time column B something like this could work - again calling for the rules - the sample workbook would make answering easier (especially that you described your layout as sheet1 and sheet2, and A1, A2 ... etc).
    Please Login or Register  to view this content.
    PS. before answering - Do please edit your post and use code tags.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA with sum and vlook up

    Hi,

    The way I'd approach this is to use a formula in say B1 on sheet1 which records the row number on sheet 2 that contains the name in A1. i.e.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    name this cell say "Row"

    Now the macro attached to your button would be.

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Registered User
    Join Date
    10-23-2014
    Location
    Liverpool
    MS-Off Ver
    2010
    Posts
    12

    Re: VBA with sum and vlook up

    sheet 2 now looks like this
    Sheet 2

    John 1 0
    Dave 2 0
    Ben 3 0
    Bob 4 0
    Can we use Vlook up to get the row number as collum c will never change. This is the first time i have ever used a Macro/ VBA.

  6. #6
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: VBA with sum and vlook up

    As we are probably talking about different layouts - attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  7. #7
    Registered User
    Join Date
    10-23-2014
    Location
    Liverpool
    MS-Off Ver
    2010
    Posts
    12

    Re: VBA with sum and vlook up

    I have attached data,

    So if some clicked commit in the sheet titled "time" collum b5 would get + cell g8 from "Calculator" sheet
    Attached Files Attached Files

  8. #8
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: VBA with sum and vlook up

    So it's exactly as I wrote - the only difference is in sheet names
    Please Login or Register  to view this content.
    see attachment
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    10-23-2014
    Location
    Liverpool
    MS-Off Ver
    2010
    Posts
    12

    Re: VBA with sum and vlook up

    Thank you so much :D

  10. #10
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: VBA with sum and vlook up

    you are welcome. would be nice if you mark therad as solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VLOOK-UP Help
    By dsheets05 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-07-2014, 06:24 AM
  2. if then or vlook up
    By denfan in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-03-2014, 04:03 PM
  3. Need help with vlook up.
    By JOONA in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-04-2013, 07:09 AM
  4. [SOLVED] VBA Vlook Up
    By NeedForExcel in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-19-2013, 05:35 AM
  5. vlook up
    By arcticale in forum Excel General
    Replies: 1
    Last Post: 01-25-2006, 05:40 PM

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