+ Reply to Thread
Results 1 to 9 of 9

VBA code to paste one value the number of times specified in a cell

  1. #1
    Registered User
    Join Date
    08-03-2012
    Location
    Edmonton, Alberta, Canada
    MS-Off Ver
    Excel 2007
    Posts
    11

    Question VBA code to paste one value the number of times specified in a cell

    Hi All!
    Helps please...
    I am creating a custom timesheet in Excel but upon submission I'm trying to paste the Employee name into the 'submissions' tab only as many times as there are filled out lines in the timesheet. I have a feeling the solution is quite simple...
    Here's my code snippet so far:

    Please Login or Register  to view this content.
    Any pointing me in the right direction is greatly appreciated! :confused:

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA code to paste one value the number of times specified in a cell

    Where does the timesheet data start and how is it laid out?

    Where exactly do you want to put the employee name?

    Can you upload an example workbook with dummy data?

  3. #3
    Registered User
    Join Date
    08-03-2012
    Location
    Edmonton, Alberta, Canada
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: VBA code to paste one value the number of times specified in a cell

    I'm locked down pretty tight here at work so I can't upload anything, but I can paste more code and describe a little furhter:

    All data entry fields on the timesheet are named ranges.

    Columns are set up as follows:
    Line Project Phase Task Description Priority Sun Mon Tue Wed Thu Fri Sat Hrs per PPT
    1
    2
    3
    4
    5

    If lines 1 through 4 have data entered I want the macro to see that it should copy & paste the employee name (in named EEName range) into the submissions tab into the next 4 blank rows in column A.

    Here's the whole pile 'o' code:
    (I have various letters of the alphabet for each section because everything was added in stages for this project and I was having a hard time keeping track of where I was... still a noob at this)

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA code to paste one value the number of times specified in a cell

    Would have been good to see the workbook but I understand your position.

    Anyway, try this which relies on a few assumptions, eg data in time sheet starts on row 2.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-03-2012
    Location
    Edmonton, Alberta, Canada
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: VBA code to paste one value the number of times specified in a cell

    Pretty close, but the headers are on row 7/8 (merged, wrapped) and data entry is on rows 10 to 21. When I tried throwing these two lines in there I ended up with it posting the EE name 11 times when there were 4 rows of data.
    I tried switching the reference but no go. I'm still too green.
    I think I can post of copy of my workbook from home this eve...

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA code to paste one value the number of times specified in a cell

    You should just need to adjust the minus one, to take account of the other rows.

    This is just another guess, I'm thinking that the merged cells may be a problem.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-03-2012
    Location
    Edmonton, Alberta, Canada
    MS-Off Ver
    Excel 2007
    Posts
    11

    Thumbs up Re: VBA code to paste one value the number of times specified in a cell

    It works! Woo hoo!
    I just had to switch the row to -8 and switch out column B for the project column and poof! It is done.
    Thank you Norie, I am so happy you helped me, even without seeing the original book.
    I can't wait for the day when I'm not such a newbie I will understand how I can write this stuff so short & sweet like you did...

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA code to paste one value the number of times specified in a cell

    Glad you were able to fix my flawed code.

  9. #9
    Registered User
    Join Date
    08-03-2012
    Location
    Edmonton, Alberta, Canada
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: VBA code to paste one value the number of times specified in a cell

    Phooey. Turns out it doesn't work...
    The problem seems to be that I am referencing all of a column - ("B") in the example below - but I have 12 lines of timesheet entry space and then summary totals below it.
    So when I use End(xlUp) for column "K" (the only column filled out for every line in use) I land in my summary totals section...
    What I really need it to tell me is:
    Within range K10:K21 (or "Priority" is the same named range) I want to know the number of lines used (always between 1 and 12).

    Unfortunately just switching "K" to my named range "Priority" or the cell range "K10:K21" doesn't work.

    I'm not sure how to modify the NoEntries line, in this case. It seems the 2nd line is working otherwise.

+ 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