Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    149
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Decipher Line of Code

    Hi Experts,

    I have two goals with this thread question:

    1. To learn techniques you used to decipher code when you were learning VBA. What resources did you use?
    2. To understand the following line of code.


    ActiveSheet.Name = Mid(Replace(wsSrc.Cells(1, 9), "Assets for ", ""), 1, 3) & Mid(wsSrc.Cells(1, 9), Len(wsSrc.Cells(1, 9)) - 4)


    Thanks for any help provided

  2. #2
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,632
    Thanks
    115
    Thanked 645 Times in 589 Posts
    Here are some useful tips on debugging:
    http://windowssecrets.com/forums/sho...ight=debugging

    The line of code will remove the instances of "Assets for" in the value wsSrc.Cells(1, 9) . it will then find the first 3 and last 5 letters of the entire string to combine to make one make one word then give the active sheet that word as a name.

    ex. The Assets for the company are the same as the Assets for the country are the same as the Assets for the globe are the same as the Assets for the Universe
    result: Theverse

    Seems that this would be an easier approach:
    Code:
    strng = Replace(Cells(1, 9), "Assets for ", "")
    Activesheet.Name = Left(strng, 3) & Right(strng, 5)
    HTH,
    Maud
    Last edited by Maudibe; 2015-07-18 at 15:04.

  3. The Following User Says Thank You to Maudibe For This Useful Post:

    Excelnewbie (2015-07-20)

  4. #3
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Understanding and Learning VBA

    Hi
    Maudibe has very succinctly summarised that line of code.

    The attached workbook, named stringPlay, has a macro in it that steps through the process shown in that line of code.

    I suggest that you run the macro line by line by pressing the F8 key. Hover the mouse over the variable names to see the contents in the tooltip.

    I hope it helps.

    Like most others I learned by recording macros and examing the code. I then started looking at the coding of others. I received a lot of help from lounge members as I started out. I would not call myself an expert and to this day rely on questioning others for help.

    This community is an amazing place. I am always amazed at the time the admins and moderators give to the cause.

    Google is your friend.

    G
    Attached Files Attached Files

  5. The Following 2 Users Say Thank You to geofrichardson For This Useful Post:

    Excelnewbie (2015-07-20),Maudibe (2015-07-19)

  6. #4
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    149
    Thanks
    67
    Thanked 0 Times in 0 Posts
    Maud-

    Thank you for the simplified code and explanation. This is very helpful to me.

  7. #5
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    149
    Thanks
    67
    Thanked 0 Times in 0 Posts
    geofrichardson,

    Thanks to you. I found it very helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •