+ Reply to Thread
Results 1 to 4 of 4

VBA Macro - If statement based on length of text

  1. #1
    Registered User
    Join Date
    02-11-2014
    Location
    Dover, Kent
    MS-Off Ver
    Excel 2010
    Posts
    3

    VBA Macro - If statement based on length of text

    Hey guys

    I'm having a bit of trouble with a macro designed to read the length text in a cell and if it = a certain length then perform an action (in this case Text to column)

    Here is a small sample of the data I'm working with:
    Tue 02/11/2014
    LastBootUpTime
    20140211082244.222441+000 <<

    Tue 02/11/2014
    LastBootUpTime
    20140211082244.222441+000 <<

    Tue 02/11/2014
    LastBootUpTime
    20140211082244.222441+000 <<

    Tue 02/11/2014
    LastBootUpTime
    20140211082244.222441+000 <<

    Tue 02/11/2014
    LastBootUpTime

    Tue 02/11/2014
    LastBootUpTime
    20140211082244.222441+000 <<
    *End Sample*

    The text length I want it to perform the action on is highlighted with "<<" if the length of text does not meet the required number then I want the statement to skip and move onto the next one.

    I have the text to column code already done with relative references however the long text string I want the statement activated on is not always present which means that the pattern (0,3) is not always consistent.

    Any help would be greatly appreciated.

    Chris

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Macro - If statement based on length of text

    Chris

    Can you post the code you have?

    Also, some sample data would be useful.

    To upload an example workbook:

    Click on GO ADVANCED and use the paperclip icon to open the upload window.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    02-11-2014
    Location
    Dover, Kent
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: VBA Macro - If statement based on length of text

    thanks for the speedy reply and apologies for the lack of speed in mine.

    Attached is my workbook with a small sample of data.

    The purpose of my project is this (if it helps):
    I have knocked together a command prompt script that remotely checks the uptime of various PCs around my work and the local time that the script was run and outputs the results to a .CSV file so it can be easily read by excel.

    The problem is that if the remote pc is off it reports one blank line rather than the two lines of uptime data that would ordinarily be reported. This means that my data does not follow a consistent pattern and this means I cannot use relative references in a loop as I hoped. What I need is an IF statement that will check every line of data and if the line meets the text length required then it will activate and perform an action (I can sort out the action myself) if it does not meet the text length then I need it to skip onto the next line until there is no data left to check.

    Apologies if I am unclear in anyway and thank you in advance for your time.

    Chris
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    02-11-2014
    Location
    Dover, Kent
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: VBA Macro - If statement based on length of text

    I ended up solving the issue for myself, but thank you for your time anyway

    For those who wish to know this is how I did it:
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    On Error GoTo endsub

    Dim x As Integer
    Dim y As String

    y = ActiveCell
    x = Len(ActiveCell)


    If Len(ActiveCell) = 25 Then GoTo actionsection

    (Other Action if criteria not met here)

    Actionsection:
    (Whatever you want it to do when it meets the criteria)

    Application.ScreenUpdating = True
    Application.DisplayAlerts = True

+ 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. Automating Row Height Based on the Length of Text
    By hvitzthum in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-12-2013, 12:21 PM
  2. [SOLVED] =COUNTIFS with condition based on length of text string
    By sunsoar77 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-25-2012, 02:25 AM
  3. [SOLVED] Automatically conditionally format font size based on text length
    By rh2705 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-09-2012, 10:47 PM
  4. Countif Based Upon Text Length
    By tralls in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-26-2006, 12:40 AM
  5. [SOLVED] Sizing Autoshapes based on text length
    By Nick Hebb in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-06-2005, 11:40 AM

Tags for this Thread

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