Jump to content
  • Welcome!

    Register and log in easily with Twitter or Google accounts!

    Or simply create a new Huddle account. 

    Members receive fewer ads , access our dark theme, and the ability to join the discussion!

     

Any Excel gurus here? Need help with a work problem and VBA.


C47

Recommended Posts

 I work with a lot of alphanumeric and numeric characters that look something like this...
00D184500
002A08800
00209100
00209200
0B3651300
07127400
07131000
0AF8230100
08310400
08310500
0H8310600
08701300
08741400
0T8741600
08741800
 
Up until now, they've only had leading zeros I need to remove, but now we're getting some with both leading and trailing zeros. What I need is a formula (preferably a VBA macro I can easily just shortcut to) to remove both the leading and trailing zeros from strings of data like this. These values would be formatted as text in the data sheets I'm working with. I was able to modify a formula I found online (see below) to remove leading zeros, so I really only need the trailing ones. Would it be possible to edit this into my working macro, or do I need to create a new macro for trailing?
 
Here's the macro I'm using to remove the leading zeros and it's working flawlessly...
 
Option Explicit
Sub removezeros()
 
Dim myCell As Range
Dim myRng As Range
Dim iCtr As Long
 
With Worksheets("Sheet1")
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
For Each myCell In myRng.Cells
For iCtr = 1 To Len(myCell.Value)
If Mid(myCell.Value, iCtr, 1) <> "0" Then
Exit For
End If
Next iCtr
myCell.Value = Mid(myCell.Value, iCtr)
Next myCell
End With
 
End Sub
 
Anybody have any experience with VBA and can help me out here?
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


  • PMH4OWPW7JD2TDGWZKTOYL2T3E.jpg

  • Topics

  • Posts

    • We definitely overpaid but as long as he's not lined up at NT he's been a starter level player which is a major step in the right direction compared to last year's D-line.  Because of his contract he'll definitely be here next year, but I fully expect him to be a cap casualty next offseason.  We'd save 15M in cap space if we cut him in 2027. I don't think he sees year 3 of his deal. I'd be open to keeping him around in 2027 but his deal would have to be reworked to a substantially lower number. 
    • Getting left out in favor of less-deserving Alabama is an honor bestowed upon a new team every year. Miami should take pride in back-to-back 10-win seasons for the first time in decades. As long as this doesn't cripple their program like it did FSU, they should be able to go for another one next year.  And, being someone who also likes to see Miami do well but knows its penchant for horribly timed losses, there's a great chance they don't find a way to beat UVa or Duke last night regardless of the matchup on paper. 
    • Truth be told, I just like a 4-3 defense better and I'll just jump in with any chance to make that statement. Seemed like an opportune moment.  
×
×
  • Create New...