Solved

Cut/remove characters from a Cell after 20 VBA

Posted on 2014-11-02
7
90 Views
Last Modified: 2014-11-04
The formula below was working ok but after some other changes, ....it's doing weird stuff to column A (adding "t" to the beginning and "xt" to the end of whatever is in column A whenever it finds more than 25 characters in a cell in Column H.

'    Sheets("Sheet1").Select
'    Columns("H:H").Select
'    For Each cell In Range("H:H").CurrentRegion  'Edit to desired range
'    cell.Value = Left(cell, 25)
'    Next cell

Is there a better way?

Thanks,

swjtx99
0
Comment
Question by:swjtx99
  • 3
  • 2
  • 2
7 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 40418717
You should trim the value property of the cells:
cell.Value = Left(cell.Value, 25)

Open in new window

0
 

Author Comment

by:swjtx99
ID: 40418744
Hi Aikmark,

Thanks. For some reason it's still changing the cell formats for every other cell on the row. I thought it was just column A but it's messing with every other cell too.

Regards,

swjtx99
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40418763
please post your workbook
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 18

Accepted Solution

by:
krishnakrkc earned 500 total points
ID: 40418774
    Dim r   As Range
    
    With Sheets("Sheet1")
        Set r = Intersect(.UsedRange, .Columns("h:h")) 'adjust Col H to suit
    
        For Each cell In r 'Edit to desired range
            cell.Value = Left(cell, 25)
        Next cell
    End With

Open in new window

0
 

Author Closing Comment

by:swjtx99
ID: 40420873
Thanks Krishnakrkc,

Works great although I still don't know why my original code messes with the formats of all cells on the row. Any idea?

Thanks,

swjtx99
0
 

Author Comment

by:swjtx99
ID: 40420874
Hi Aikimark,

Sorry I was unable to post the workbook. It has info I can't post. Thanks for trying.

swjtx99
0
 
LVL 18

Expert Comment

by:krishnakrkc
ID: 40421399
That's because you were using the currentregion property of the cell.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question