+ Reply to Thread
Results 1 to 18 of 18

VBA - Creating a macro for reducing text in cell

  1. #1
    Registered User
    Join Date
    05-20-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    18

    VBA - Creating a macro for reducing text in cell

    Guys,

    I have been pointed here from another thread as am trying to create a VBA macro that when I press a button the following occurs....


    Column B (the date and time) reduced from "20190520 07:38:31.332442 +0000" to just "20190520" which just shows the date.

    and

    Column U reduced from "20190520 07:38:31.332442 +0000" to just "07:38:31"

    and

    IF Cell A2 is populated then Cell N2 will be populated with "N" (unless i overwrite)

    Of course I will have multiple lines on the spreadsheet so we assume the macro will perform this across all lines.

    thanks in advance

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA - Creating a macro for reducing text in cell

    Please Login or Register  to view this content.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: VBA - Creating a macro for reducing text in cell

    Possibly...
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-20-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    18

    Re: VBA - Creating a macro for reducing text in cell

    Thanks so far, but that doesn't look to have worked.

    I need all date timestamps in column B to be reduced from "20190520 07:38:31.332442 +0000" to just "20190520". So essentially the time removed and just leaving that date format.

    then

    IF cells in column A are populated then the cell in the same line in column N will be populated with "N" (unless i overwrite).

    then

    All populated cells in column U reduced from "20190520 07:38:31.332442 +0000" to just "07:38:31" which is just the time HH:MM:SS.


    Spreadsheets are now attached for you to look at with what I would like the lines to look like after the macro has run.
    Attached Files Attached Files
    Last edited by moreno5; 05-21-2019 at 03:58 AM.

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: VBA - Creating a macro for reducing text in cell

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  6. #6
    Registered User
    Join Date
    05-20-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    18

    Re: VBA - Creating a macro for reducing text in cell

    Quote Originally Posted by Marc L View Post
    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Thanks Marc, didn't scroll down to see "Manage Attachments". Thanks for your efforts.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,568

    Re: VBA - Creating a macro for reducing text in cell

    Quote Originally Posted by moreno5 View Post
    Column B (the date and time) reduced from "20190520 07:38:31.332442 +0000" to just "20190520" which just shows the date.

    Column U reduced from "20190520 07:38:31.332442 +0000" to just "07:38:31"
    try
    Please Login or Register  to view this content.
    Quote Originally Posted by moreno5 View Post
    IF Cell A2 is populated then Cell N2 will be populated with "N" (unless i overwrite)
    Of course I will have multiple lines on the spreadsheet so we assume the macro will perform this across all lines.
    Don't understand above.

  8. #8
    Registered User
    Join Date
    05-20-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    18

    Re: VBA - Creating a macro for reducing text in cell

    Quote Originally Posted by jindon View Post
    try
    Please Login or Register  to view this content.

    Don't understand above.

    Essentially if a cell is populated in column A...for example A3 has an ID then N3 should be populated with an "N". The same would go for if an ID was now in cell A4 then N4 should be populated with an "N".

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,568

    Re: VBA - Creating a macro for reducing text in cell

    Not really sure for the second part.
    This will change to "N", if Col.A<>"" and Col.N = "", and no change if col.N has some value already.
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !

    Quote Originally Posted by moreno5 View Post
    Thanks Marc, didn't scroll down to see "Manage Attachments". Thanks for your efforts.
    A starter to paste to the Options booking worksheet module :

    PHP Code: 
    Sub Demo1()
        
    With [A1].CurrentRegion.Rows("2:" & [A1].CurrentRegion.Rows.Count).Columns
            
    .Item(2).Value Evaluate("IF({1},LEFT(" & .Item(2).Address ",8))")
            .
    Item(14).Value Evaluate("IF(" & .Item(1).Address ">"""",""N"","""")")
            .
    Item(21).Value Evaluate("IF({1},MID(" & .Item(21).Address ",10,8))")
        
    End With
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  11. #11
    Registered User
    Join Date
    05-20-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    18

    Re: VBA - Creating a macro for reducing text in cell

    Quote Originally Posted by jindon View Post
    Not really sure for the second part.
    This will change to "N", if Col.A<>"" and Col.N = "", and no change if col.N has some value already.
    Please Login or Register  to view this content.
    Perfect! That worked superbly. Thank you very much for your help.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,568

    Re: VBA - Creating a macro for reducing text in cell

    You are welcome and thanks for the rep.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVE

  13. #13
    Registered User
    Join Date
    05-20-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    18

    Re: VBA - Creating a macro for reducing text in cell

    Actually, sorry to be cheeky....just one last thing as it has worked so nicely.

    Any chance we can have it so that again like with the first one where if cell A is populated with anything then cell N in the same line is populated with an "N"....can we also have the following populated into cell V on the same line "ICE.IFLO"

    thanks

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,568

    Re: VBA - Creating a macro for reducing text in cell

    Try change to
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    05-20-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    18

    Re: VBA - Creating a macro for reducing text in cell

    Superb and thank you.

  16. #16
    Registered User
    Join Date
    05-20-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    18

    Re: VBA - Creating a macro for reducing text in cell

    Hi Jin,

    I have just found that I will need need to divide all the prices in column H by 100 with the macro also.

    So again, is it possible to have that if cell A on the same line is populated, the figure populated in Cell H of the same line is divided by 100 (So A3 is populated then divide H3 by 100).

    thanks,

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,568

    Re: VBA - Creating a macro for reducing text in cell

    Try change to
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    05-20-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    18

    Re: VBA - Creating a macro for reducing text in cell

    Thanks again!

+ 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. [SOLVED] MACRO: determine if cell contains text then paste one cell down (creating a list)
    By ThomasAnthony in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-21-2016, 01:57 PM
  2. Replies: 1
    Last Post: 05-20-2015, 04:27 PM
  3. [SOLVED] Reducing macro for borders
    By ds0919 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-31-2012, 12:28 PM
  4. reducing cluster in line of macro
    By jw01 in forum Excel General
    Replies: 8
    Last Post: 04-05-2012, 11:18 AM
  5. Creating a macro: If Cell A1 contains x then add x to the end of a string of text.
    By Coolcatfish in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-27-2012, 11:15 AM
  6. Replies: 3
    Last Post: 09-29-2009, 11:52 AM
  7. [SOLVED] how to stop text size from reducing in TextBoxes in Excel
    By Ralph Boyce in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-23-2006, 04:10 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