+ Reply to Thread
Results 1 to 22 of 22

Button to populate cells

  1. #1
    Registered User
    Join Date
    10-23-2019
    Location
    OHIO
    MS-Off Ver
    office 2013
    Posts
    84

    Button to populate cells

    Hi guru's

    I need to be able to create a button that when i click it it populates cells with generic data from the blank rota sheet.

    Ideally i want it to only generate each block of cells and have a button for each group of bordered cells.

    Is this possible and as each week another tab is added to the bottom would it be possible to make the button update the specific sheet im working on at the time?

    attached is an example copy of the excel document so far.

    I look forward to hearing from you all :D
    Attached Files Attached Files

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Button to populate cells

    Jon,

    per you: I need to be able to create a button that when i click it it populates cells with generic data from the blank rota sheet.

    that's very vague. you really should give specifics. you mean you want a button to produce a new sheet that looks exactly like the sheets ""0908"" and ""1608"", every month as a new worksheet?

    per you: would it be possible to make the button update the specific sheet im working on at the time

    of course. but it's still a little vague.

  3. #3
    Registered User
    Join Date
    10-23-2019
    Location
    OHIO
    MS-Off Ver
    office 2013
    Posts
    84

    Re: Button to populate cells

    I thought it was quite straight forward but i guess i can elaborate a little more?

    I want to copy from for example the Blank rota tab b18:h19 and past it in the current worksheet at the click of a button on the active sheet using vba, as the tabs go up each week i want to be able to copy generic data from blank rota to the newest tab i selected.

    is this possible?

  4. #4
    Registered User
    Join Date
    10-23-2019
    Location
    OHIO
    MS-Off Ver
    office 2013
    Posts
    84

    Re: Button to populate cells

    Ok so this code works if i want it copying to the specific tab 2308 but i want it work on every tab automatically without having to change it each time.


    Sub copy_range()

    Dim FirstSheet As Worksheet
    Set FirstSheet = ActiveWorkbook.Worksheets("BLANK ROTA")
    Dim SecondSheet As Worksheet
    Set SecondSheet = ActiveWorkbook.Worksheets("2308")

    FirstSheet.Range("B18:H19 ").Copy
    SecondSheet.Range("B18:H19").PasteSpecial Paste:=xlValues 'Only paste values

    End Sub
    Last edited by JON_ROCKS; 08-17-2020 at 07:06 AM.

  5. #5
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Button to populate cells

    Quote Originally Posted by JON_ROCKS View Post
    I thought it was quite straight forward but i guess i can elaborate a little more?

    I want to copy from for example the Blank rota tab b18:h19 and past it in the current worksheet at the click of a button on the active sheet using vba, as the tabs go up each week i want to be able to copy generic data from blank rota to the newest tab i selected.

    is this possible?
    of course. your file has plenty of modules and code already in it. did you write all of that? all you need to do here is use the RANGE() object in code. select the range, copy it and select the cell on the worksheets of choice and paste in it in your desired place. when you insert a NEW tab, regardless of where it appears on the bottom of the screen in the list of worksheets, it automatically becomes the upper bound index number of the worksheets collection, I believe. thus, to point to it, this code should work:

    Please Login or Register  to view this content.
    keep in mind, VBA is not the greatest language in the world, certainly not like Python, so some interchangeable code (e.g. - statements that can be written more than one way) sometimes don't work the same. you can thank microsoft for that. (sigh)

  6. #6
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Button to populate cells

    looks like you already worked it out. so, you can use what I just said regarding bounds to accomplish your goal

  7. #7
    Registered User
    Join Date
    10-23-2019
    Location
    OHIO
    MS-Off Ver
    office 2013
    Posts
    84

    Re: Button to populate cells

    Quote Originally Posted by vba_php View Post
    of course. your file has plenty of modules and code already in it. did you write all of that? all you need to do here is use the RANGE() object in code. select the range, copy it and select the cell on the worksheets of choice and paste in it in your desired place. when you insert a NEW tab, regardless of where it appears on the bottom of the screen in the list of worksheets, it automatically becomes the upper bound index number of the worksheets collection, I believe. thus, to point to it, this code should work:

    Please Login or Register  to view this content.
    keep in mind, VBA is not the greatest language in the world, certainly not like Python, so some interchangeable code (e.g. - statements that can be written more than one way) sometimes don't work the same. you can thank microsoft for that. (sigh)
    Hi,

    Alot of them but not all , most were adapted from things ive found in google,

    I am fairly new to this so just forming a basic understanding,


    How would i impliment your suggestion into the code i posted above to make it work please?

  8. #8
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Button to populate cells

    try this Jon.

    Please Login or Register  to view this content.
    should work.

  9. #9
    Registered User
    Join Date
    10-23-2019
    Location
    OHIO
    MS-Off Ver
    office 2013
    Posts
    84

    Re: Button to populate cells

    i get run time error 9 subscript out of range error?

  10. #10
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Button to populate cells

    no kidding? hmmmmm....i wonder if I forgot a line!:

    Please Login or Register  to view this content.
    that work?

  11. #11
    Registered User
    Join Date
    10-23-2019
    Location
    OHIO
    MS-Off Ver
    office 2013
    Posts
    84

    Re: Button to populate cells

    no luck mate i now get error 424 object required

  12. #12
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Button to populate cells

    well....maybe it's a little too early. I've checked numerous ways on my end and it works fine. can you upload the file with the new code? and, I'm not a professional excel developer so there's possibly something I'm missing? I don't know.

  13. #13
    Registered User
    Join Date
    10-23-2019
    Location
    OHIO
    MS-Off Ver
    office 2013
    Posts
    84

    Re: Button to populate cells

    ive just pasted it into the attached spreadsheet in the first post into a new module

  14. #14
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Button to populate cells

    Jon,

    I looked at every module and I don't see the routine name I posted for you anywhere in there. are you sure you included it? I don't see anything similar to what I did either. where is the code at? what module? name of it please?

  15. #15
    Registered User
    Join Date
    10-23-2019
    Location
    OHIO
    MS-Off Ver
    office 2013
    Posts
    84

    Re: Button to populate cells

    hi i havent re uploaded it since doing it mate but i am using a copy of that document

  16. #16
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Button to populate cells

    Quote Originally Posted by JON_ROCKS View Post
    hi i havent re uploaded it since doing it mate but i am using a copy of that document
    and that means? that means it should be there in the original in your first post? if so, I already told you I looked at it and my example is not in there. sorry....does it have a different name?

  17. #17
    Registered User
    Join Date
    10-23-2019
    Location
    OHIO
    MS-Off Ver
    office 2013
    Posts
    84

    Re: Button to populate cells

    ok added this check module 31
    Attached Files Attached Files

  18. #18
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Button to populate cells

    you had the new worksheet named wrong you goofy guy! LOL. plus, the macro recorder spits out more than just this argument in the pasteSpecial method (which is what you had. not sure if you need all the rest of the args that excel made for me):
    Please Login or Register  to view this content.
    the entire things that works here is:

    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    10-23-2019
    Location
    OHIO
    MS-Off Ver
    office 2013
    Posts
    84

    Re: Button to populate cells

    DOH!! yep working perfect now thanks for your help!

  20. #20
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Button to populate cells

    Well it don't only took 50 million posts John. Glad to hear that it worked! Good luck to you on your project. And sorry about the spelling of your name artificial intelligence on phones is really terrible! LOL

  21. #21
    Registered User
    Join Date
    10-23-2019
    Location
    OHIO
    MS-Off Ver
    office 2013
    Posts
    84

    Re: Button to populate cells

    SOOO.... one last question, can a click to confirm popup box be added to this code so it doesnt accidentally over write all the work?

  22. #22
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Button to populate cells

    Quote Originally Posted by JON_ROCKS View Post
    SOOO.... one last question, can a click to confirm popup box be added to this code so it doesnt accidentally over write all the work?
    of course it can. all visual basic languages and its extensions (VBA, VB 2.0 - 6.0, VBS, VB.NET) have the message box object inside of them. so, for this particular flavor, it is simple:
    Please Login or Register  to view this content.

+ 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. Populate specific cells from sheet 1 to sheet 2 with a checkbox and a button
    By robv5712 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2020, 10:26 AM
  2. Trouble with macro for Button to selectively populate cells
    By Chondrulos in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2018, 12:54 AM
  3. Option button to populate text box
    By donkey_uk in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-13-2015, 02:57 PM
  4. [SOLVED] browse button to populate a combobox
    By jed38 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-06-2013, 12:59 PM
  5. Using a button to populate 3 cells in a row.
    By aeewing1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-23-2013, 09:23 AM
  6. Populate next row on button click
    By bangorgav in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-19-2012, 07:29 AM
  7. Populate Worksheet with Command Button
    By taichi56 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-23-2008, 09:06 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