+ Reply to Thread
Results 1 to 9 of 9

I need help with cleaning up some ugly Macro Code.

  1. #1
    Registered User
    Join Date
    10-13-2014
    Location
    Assen, The netherlands
    MS-Off Ver
    2013
    Posts
    27

    I need help with cleaning up some ugly Macro Code.

    Hi All,

    I made some ugly macro code.
    It functions, but I do know it's not the "standard" way to get my trick done.

    Here's some of the code:

    Please Login or Register  to view this content.
    I only need the value from Userform3 to be placed into the fields.
    As I don't know how else to achieve this, I made a range, and that works.
    But I'm sure it must be possible to point it to a cell.
    To make it simple, the code I used : "Set lastrowD = ws.Range("D13:D14").Find" makes a range from D13 to D14, but as it add's 1, it's always D14.
    And D14 is also the field that requires the value of that (name) field of the Userform3.

    It's ugly. But it works ! And I'm happy about that

    Next code that needs to be simplified:

    Please Login or Register  to view this content.
    I need a nice PrintOut, and I need 2 copies.
    Tons of information on the WWW about printing, but how to make a simple duplicate copy? I really did search (for over 2 hours, then i gave up).
    This code of mine works, it does the trick, but I'm sure there is a better way!

    That's all for today

    All the help is appreciated!
    Attached Files Attached Files
    Last edited by Fhorst; 10-22-2014 at 06:57 PM. Reason: Solved :)

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: I need help with cleaning up some ugly Macro Code.

    As you would find in Help,

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    10-13-2014
    Location
    Assen, The netherlands
    MS-Off Ver
    2013
    Posts
    27

    Re: I need help with cleaning up some ugly Macro Code.

    Thanks!

    I did not look in the "Help"
    Google usually gives better help then the build-in help, but in this case....

  4. #4
    Registered User
    Join Date
    03-12-2014
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: I need help with cleaning up some ugly Macro Code.

    Fhorst. I'm assuming you're looking at pasting data on to Empty cells in Excel sheet? Sorry if that isn't the case the post isn't very clear.

    However if that is the case you could use a more clearer method. Use the below code.

    Please Login or Register  to view this content.
    The method could've been shorter if your controls were named similar with numeric order..

  5. #5
    Registered User
    Join Date
    10-13-2014
    Location
    Assen, The netherlands
    MS-Off Ver
    2013
    Posts
    27

    Re: I need help with cleaning up some ugly Macro Code.

    Hi Jayesh,

    I'm sorry that I can't be more clear.
    I'll try to make it more specific:

    Klant1.Value : needs to enter in field D13 on the sheet "Factuur"
    Adres1.Value : needs to enter in field D14 on the sheet "Factuur"
    Plaats1.Value : needs to enter in field D15 on the sheet "Factuur"
    Postcode1.Value : needs to enter in field G15 on the sheet "Factuur"
    Telefoon1.Value : needs to enter in field D16 on the sheet "Factuur"
    Email1.Value : needs to enter in field G16 on the sheet "Factuur"
    Werkbon_nr1.Value : needs to enter in field N14 on the sheet "Factuur"
    Kenteken1.Value : needs to enter in field N15 on the sheet "Factuur"
    km_stand1.Value : needs to enter in field N16 on the sheet "Factuur"

    Thanks!

  6. #6
    Registered User
    Join Date
    03-12-2014
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: I need help with cleaning up some ugly Macro Code.

    Well If it's a fixed cell you'd like your values to be pasted on then you could directly refer them to a cell range as below.

    Please Login or Register  to view this content.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: I need help with cleaning up some ugly Macro Code.

    Or ...

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-13-2014
    Location
    Assen, The netherlands
    MS-Off Ver
    2013
    Posts
    27

    Re: I need help with cleaning up some ugly Macro Code.

    Thank you both! SHG and Jayesh25

    The code is much better this way!

    For me, the code from SHG looks like one I can follow, and edit if needed. (not that the one from Jayesh25 is not good, but one has to chose...)

    Now I still have this issue :copy values and cross check

    This post can be closed. (I think I can do that right?)

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: I need help with cleaning up some ugly Macro Code.

    You're welcome.

+ 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. Looking for help Cleaning up code
    By SmoothRider in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-20-2014, 02:58 PM
  2. [SOLVED] cleaning up code for macro with multiple tabs
    By ds0919 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-19-2013, 02:51 PM
  3. Ugly slow code....
    By Slyone2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-16-2010, 08:13 PM
  4. Sort Macro - Cleaning up code
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-25-2010, 06:29 PM
  5. Cleaning up the code after recording a macro.
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-01-2010, 02:30 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