+ Reply to Thread
Results 1 to 18 of 18

Simple VBA editing.. need some insight!

  1. #1
    Forum Contributor
    Join Date
    04-05-2007
    Location
    Arlington, TX
    MS-Off Ver
    Office 2010
    Posts
    164

    Simple VBA editing.. need some insight!

    Moving this over to the proper forum...

    Alright, I'm poked about in VBA for excel, but I'm having trouble learning how to reference a particular column to reproduce

    currently this is the original code:

    Please Login or Register  to view this content.
    What I need to do is force data from columns B, H, J on the current selected row to populate on the new row. The current code only copies the 2 existing formulas. How do you reference data from those columns on the selected row to copy down to the new row below? And lasty, how do I remove the prompt to ask how many rows to reproduce? I just want it to default to reproduce 1 single additional row.

    thanks very much for any help!

    And I appreciate your help, I'm excited to learn more about excel and using macros.
    Last edited by Pyrex238; 06-20-2007 at 10:21 AM.

  2. #2
    Forum Contributor
    Join Date
    03-24-2005
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    378

    Not Sure this will work for you

    I have a spreadsheet I use for taking minutes and assigning tasks.

    Frequent copy and insert row activities so I now have included a right-click context menu item to copy and insert a copy of the entire row where the right-click takes place.

    In ThisWorkbook I have
    Please Login or Register  to view this content.
    In a regular module I have
    Please Login or Register  to view this content.
    Thanks!
    Dennis

    I am using Windows 7 and Office 2007, all of my posts are based on this.

  3. #3
    Forum Contributor
    Join Date
    04-05-2007
    Location
    Arlington, TX
    MS-Off Ver
    Office 2010
    Posts
    164
    hmm.. I couldn't get either macro to work for some reason. Are you familiar with how to specify a particular column? All I really need to do is specify column so and so needs to be copied to the new row.

  4. #4
    Forum Contributor
    Join Date
    03-24-2005
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    378

    One thing at a time.

    First, I missed the copy a column and insert as a row.

    Is this what you really want to accomplish? A column contains 65,536 cells and a row only contains 256 cells, at least in Excel up through 2003. This is not reasonable, at least to me.

    Next, the code I show works for me, I have sent it to people in different companies with different versions of Excel and it works for them.

    Did you place the first two routines into ThisWorkbook via the VBE Window? And you put the Third Routine into a normal module?

    Let's try a little trouble shooting:
    • Insert a new sheet into your workbook that you can delete when done.
    • In cell B5 and B6 enter something different for each.
    • Select Cell B6 as the active cell.
    • Press the key combination <Alt><F8> to bring up the macro dialog
    • Select Copy_Insert_Row
    • Run the macro
    Do you now have three cells with entries(B5, B6, & B7?) Cells B6 and B7 should have the same data.

  5. #5
    Forum Contributor
    Join Date
    04-05-2007
    Location
    Arlington, TX
    MS-Off Ver
    Office 2010
    Posts
    164
    Okay, sorry for my negligence... don't know what I did... was busy earlier.

    Please Login or Register  to view this content.
    this section works great, it simply copies the row. However, I'm looking to copy only a few cells down.

    I need to copy the following cells in the currently selected row ... cells in column B, F&G - these are formulas specific to that exact row so I need it to copy the formula down to the new row, but change the row number in the formula - much like the fill function does, and H.

    I can't figure out how to do this.. been reading for a while.

  6. #6
    Forum Contributor
    Join Date
    03-24-2005
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    378

    Oops...

    I applogize, I just read the entire thread again.

    I will modify my routine to insert a single new row, and copy the formula from the previous row cells in columns B, H, & J into the same columns in the new row.

  7. #7
    Forum Contributor
    Join Date
    04-05-2007
    Location
    Arlington, TX
    MS-Off Ver
    Office 2010
    Posts
    164
    Quote Originally Posted by DCSwearingen
    I applogize, I just read the entire thread again.

    I will modify my routine to insert a single new row, and copy the formula from the previous row cells in columns B, H, & J into the same columns in the new row.
    I really appreciate your time. I'm still getting accustomed to programming macros, and learning all of the excel triggers and syntax.

    How exactly do you reference a column within a row? - that is my major hang up .. recording macros only grabs a specific cell, but not a column within the row... allowing it to be unique for each row.

  8. #8
    Forum Contributor
    Join Date
    03-24-2005
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    378

    Use With Caution

    This all depends on relative referencing in formulas and not ansolute referencing.

    Also, formulas in the row pushed down will still reference the original row and do not change to reference the new row.

    If that is what you want then this should work.

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Thanks for wrapping your code

    How exactly do you reference a column within a row? - that is my major hang up .. recording macros only grabs a specific cell, but not a column within the row... allowing it to be unique for each row.
    These snippets may help

    Please Login or Register  to view this content.
    will return column number

    Please Login or Register  to view this content.
    Will look at row 3 and activecolumn number to return address.

    Please Login or Register  to view this content.
    is a range from Row1 & column to Row 5 and Column

    This link may also help

    http://msdn2.microsoft.com/en-us/lib...ffice.11).aspx

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  10. #10
    Forum Contributor
    Join Date
    04-05-2007
    Location
    Arlington, TX
    MS-Off Ver
    Office 2010
    Posts
    164
    Quote Originally Posted by DCSwearingen
    This all depends on relative referencing in formulas and not ansolute referencing.

    Also, formulas in the row pushed down will still reference the original row and do not change to reference the new row.

    If that is what you want then this should work.

    Please Login or Register  to view this content.

    Thanks for all the great info. That code does work for me.. what I don't understand is the digits being used... colH = Cells(myRow, 8).Address for example - column H is the 7th column, why is it referred to as 8? - pardon my novice. The formula does work! I just need to get my formulas from column F&G to pull down as well and I finally have my dream realized! If I use the code above referenced, it doesnt pull a formula unique to those cells, just copies the exact formula above... what would bet he process for that?

  11. #11
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Check your maths. Col H is the 8th Column

    VBA Noob

  12. #12
    Forum Contributor
    Join Date
    04-05-2007
    Location
    Arlington, TX
    MS-Off Ver
    Office 2010
    Posts
    164
    Quote Originally Posted by VBA Noob
    Check your maths. Col H is the 8th Column

    VBA Noob
    HA! I deleted my "D" column! the math was right, the alphabet wasn't!

  13. #13
    Forum Contributor
    Join Date
    03-24-2005
    Location
    Wisconsin
    MS-Off Ver
    2007
    Posts
    378

    Even if you deleted

    Quote Originally Posted by Pyrex238
    HA! I deleted my "D" column! the math was right, the alphabet wasn't!
    Deleting Column D would simpply shift the columns to the left. Column D must have been hidden.

    One simple way to double check was in VBA Noob's earlier response.

    Another that I took was to write myself a simple macro and put it in PERSONAL.XLS.
    Please Login or Register  to view this content.
    I then put a macro button assigned to this on my Standard toolbar. I just set the image on the button to read R1C1, and clicking it will change the column headers back and forth between R1C1 notation and A1 Notation.

    No counting involved, just observe what the changes are.

  14. #14
    Forum Contributor
    Join Date
    04-05-2007
    Location
    Arlington, TX
    MS-Off Ver
    Office 2010
    Posts
    164
    alright! got it! thank you so much everyone!

    BUT! one last question... it leaves the last cell with a copy halo... how do you set the macro to deselect all cells, then select column 1 so you can begin data entry?



    ..edit:

    nevermind! I figured it out with a little intuition:

    Please Login or Register  to view this content.
    but I still have the halo... how do you remove that? ... how do you code in a keystroke? IE: Keystroke.esc - should effectively remove that halo
    Last edited by Pyrex238; 06-20-2007 at 03:25 PM.

  15. #15
    Forum Contributor
    Join Date
    04-05-2007
    Location
    Arlington, TX
    MS-Off Ver
    Office 2010
    Posts
    164
    Sendkeys "esc" works... but it just makes the new first column that is selected have a halo.

  16. #16
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Think you need

    Please Login or Register  to view this content.
    VBA Noob

  17. #17
    Forum Contributor
    Join Date
    04-05-2007
    Location
    Arlington, TX
    MS-Off Ver
    Office 2010
    Posts
    164
    Quote Originally Posted by VBA Noob
    Think you need

    Please Login or Register  to view this content.
    VBA Noob
    genius! thanks a lot

  18. #18
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Not really. Took me a while to figure out what the halo was .

    Quick tip. Use the recorder to copy the cell then double click the cell....

    VBA Noob

+ 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