Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 06-15-2009, 11:06 AM
shg's Avatar
shg shg is offline
Forum Guru
 
Join Date: 20 Jun 2007
Location: The Great State of Texas
MS Office Version:2003, 2007
Posts: 18,450
shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay
List Cell Text in Binary

Please Register to Remove these Ads

After using =Char(Mid(A1, 15, 1)), =Char(Mid(A1, 16, 1)), =Char(Mid(A1, 17, 1)), ... a few hundred times in years past, I made a form and wrote some code to list the contents of a cell in binary. It's been handy.

I recently added support for Unicode, so it may not be fully cooked (or maybe reheated), and double-width Unicode characters are problematic.

In addition to adding the attached form to the workbook, this needs to go in a code module.
Code:
Sub CSB()
    ' Shortcut: Ctrl+Shift+B, as in
    '   "conveniently show binary"
    frmShowBinary.ShowBinary
End Sub
Attached Files
File Type: zip frmShowBinary.zip (2.6 KB, 29 views)
__________________
Entia non sunt multiplicanda sine necessitate.

Last edited by shg; 06-15-2009 at 11:16 PM.
Reply With Quote
  #2  
Old 06-15-2009, 08:44 PM
shg's Avatar
shg shg is offline
Forum Guru
 
Join Date: 20 Jun 2007
Location: The Great State of Texas
MS Office Version:2003, 2007
Posts: 18,450
shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay
Literal Array Functions

I use these functions in lieu of the volatile constructs like this:

ROW(INDIRECT("1:" & A1))
COLUMN(INDIRECT(A1 & ":" & A2))


... like this:

RowArr(1, A1)
ColArr(A1, A2)


... with the added benefit of having a step variable

RowArr(1, 10, 2)

... and you can have negative numbers

RowArr(10, -5, -3)

Here 'tis.
Attached Files
File Type: zip mathLiteralArray.zip (629 Bytes, 17 views)
__________________
Entia non sunt multiplicanda sine necessitate.

Last edited by shg; 06-16-2009 at 11:26 AM.
Reply With Quote
  #3  
Old 06-15-2009, 11:44 PM
shg's Avatar
shg shg is offline
Forum Guru
 
Join Date: 20 Jun 2007
Location: The Great State of Texas
MS Office Version:2003, 2007
Posts: 18,450
shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay
What's in Your Personal.xls?

Just thought I'd share ...
__________________
Entia non sunt multiplicanda sine necessitate.
Reply With Quote
  #4  
Old 06-16-2009, 06:27 PM
shg's Avatar
shg shg is offline
Forum Guru
 
Join Date: 20 Jun 2007
Location: The Great State of Texas
MS Office Version:2003, 2007
Posts: 18,450
shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay
Re: What's in Your Personal.xls?

Ever wonder about how binary (IEEE-754) floating point numbers (the source of all those mysterious precision problems) are actually represented? The attachment has a family of functions for converting between floating point numbers and hex strings. I used a couple of these in responding to http://www.excelforum.com/excel-prog...h-queries.html.

Most work in either VBA or as worksheet functions. Here's the list:

Code:
'   Routine         Input                   Output           WF/VBA
'   -------- -------------------- -------------------------- ------
'   Byte2Sng ab(0 To 3)           Single                     VBA
'   Sng2Byte Single               4-byte array Variant       Both
'   Sng2Hex  Single               Hex String                 Both
'   Hex2Sng  Hex string           Single                     Both
'   Var2Sng  4-byte array Variant Single                     Both

'   Routine         Input                   Output           WF/VBA
'   -------- -------------------- -------------------------- ------
'   Byte2Dbl ab(0 To 7)           Double                     VBA
'   Dbl2Byte Double               8-byte array Variant       Both
'   Dbl2Hex  Double               Hex string                 Both
'   Hex2Dbl  Hex string           Double                     Both
'   Var2Dbl  8-byte array Variant Double                     Both

'   Routine         Input                   Output           WF/VBA
'   -------- -------------------- -------------------------- ------
'   Flt2Byte Single or Double     4- or 8-byte array Variant VBA
'   Byte2Hex Byte array           Hex string                 VBA
Attached Files
File Type: zip mathFloatingPoint2Byte.zip (1.8 KB, 28 views)
File Type: pdf IEEE 754 Floating Point Format.pdf (30.2 KB, 30 views)
__________________
Entia non sunt multiplicanda sine necessitate.
Reply With Quote
  #5  
Old 06-17-2009, 07:06 AM
StephenR StephenR is offline
Forum Guru
 
Join Date: 26 Aug 2007
Location: London
Posts: 2,210
StephenR is very confident of their ability StephenR is very confident of their ability StephenR is very confident of their ability StephenR is very confident of their ability StephenR is very confident of their ability
Re: What's in Your Personal.xls?

I’ll play even though by comparison, I fear I’m a bit lowbrow.

I have a number of macros which are specific to my job – organising, running checks on and analysing data.

I have a macro listing names of files in a folder, and one which extracts data from files in a folder. I have a couple of template-style macros which contain little bits of code which I tend to use more often than most (e.g. Find).

I also have a number of very short macros which I’ve assigned to buttons on a toolbar. They’re so simple but they save so much time. For example, vertically centring text, removing colours, turning off AutoFilter, centring across selection, filling selected cells with random numbers.
Reply With Quote
  #6  
Old 06-17-2009, 09:50 AM
shg's Avatar
shg shg is offline
Forum Guru
 
Join Date: 20 Jun 2007
Location: The Great State of Texas
MS Office Version:2003, 2007
Posts: 18,450
shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay
Re: What's in Your Personal.xls?

My thought was that we could use this thread as a repository of sorts, and vector people here when one of the routines might solve a problem.

Quote:
I have a macro listing names of files in a folder, and one which extracts data from files in a folder. I have a couple of template-style macros which contain little bits of code which I tend to use more often than most (e.g. Find).

I also have a number of very short macros which I’ve assigned to buttons on a toolbar. They’re so simple but they save so much time. For example, vertically centring text, removing colours, turning off AutoFilter, centring across selection, filling selected cells with random numbers.
Those sound great! How making a separate post for each?

So -- post 'em up, Stephen!
__________________
Entia non sunt multiplicanda sine necessitate.
Reply With Quote
  #7  
Old 06-18-2009, 04:16 PM
ChemistB ChemistB is offline
Forum Guru
 
Join Date: 05 Aug 2004
Location: NJ
MS Office Version:MS 2007
Posts: 2,593
ChemistB is attaining expert status ChemistB is attaining expert status
Re: What's in Your Personal.xls?

Mostly have a lot of little utility macros with shortcut keys if I use them often.
Here's one where I select all the cells in my workbook that I want to have a specific # of digits
Code:
Sub AddDecimals()
Dim x As Integer
x = Application.InputBox("No of Decimals !!", "Add Decimals", Type:=2)
If x = 0 Then
Selection.NumberFormat = "0" & WorksheetFunction.Rept(0, x)
Else
Selection.NumberFormat = "0." & WorksheetFunction.Rept(0, x)
End If
End Sub
__________________
ChemistB
My 2¢
Reply With Quote
  #8  
Old 06-18-2009, 04:17 PM
ChemistB ChemistB is offline
Forum Guru
 
Join Date: 05 Aug 2004
Location: NJ
MS Office Version:MS 2007
Posts: 2,593
ChemistB is attaining expert status ChemistB is attaining expert status
Re: What's in Your Personal.xls?

And here's one that Inserts a worksheet and lists all the formulas off the active sheet and what cells they are in
Code:
Sub ListFormulas()
    Dim FormulaCells As Range, Cell As Range
    Dim FormulaSheet As Worksheet
    Dim Row As Integer
    
'   Create a Range object for all formula cells
    On Error Resume Next
    Set FormulaCells = Range("A1").SpecialCells(xlFormulas, 23)
    
'   Exit if no formulas are found
    If FormulaCells Is Nothing Then
        MsgBox "No Formulas."
        Exit Sub
    End If
    
'   Add a new worksheet
    Application.ScreenUpdating = False
    Set FormulaSheet = ActiveWorkbook.Worksheets.Add
    FormulaSheet.Name = "Formulas in " & FormulaCells.Parent.Name
    
'   Set up the column headings
    With FormulaSheet
        Range("A1") = "Address"
        Range("B1") = "Formula"
        Range("A1:B1").Font.Bold = True
    End With
    
'   Process each formula
    Row = 2
    For Each Cell In FormulaCells
        Application.StatusBar = Format((Row - 1) / FormulaCells.Count, "0%")
        With FormulaSheet
            Cells(Row, 1) = Cell.Address _
                (RowAbsolute:=False, ColumnAbsolute:=False)
            Cells(Row, 2) = " " & Cell.Formula
            Row = Row + 1
        End With
    Next Cell
    
'   Adjust column widths
    FormulaSheet.Columns("A:B").AutoFit
    Application.StatusBar = False
End Sub
__________________
ChemistB
My 2¢
Reply With Quote
  #9  
Old 06-18-2009, 04:19 PM
ChemistB ChemistB is offline
Forum Guru
 
Join Date: 05 Aug 2004
Location: NJ
MS Office Version:MS 2007
Posts: 2,593
ChemistB is attaining expert status ChemistB is attaining expert status
Re: What's in Your Personal.xls?

I use this one a lot before protecting my workbook. It selects all unlocked cells.
Code:
Sub SelectUnlockedCells()
    Dim WorkRange As Range
    Dim FoundCells As Range
    Dim Cell As Range
    Set WorkRange = ActiveSheet.UsedRange
    For Each Cell In WorkRange
        If Cell.Locked = False Then
            If FoundCells Is Nothing Then
                Set FoundCells = Cell
            Else
                Set FoundCells = Union(FoundCells, Cell)
            End If
        End If
    Next Cell
    If FoundCells Is Nothing Then
        MsgBox "All cells are locked."
    Else
        FoundCells.Select
    End If
End Sub
__________________
ChemistB
My 2¢
Reply With Quote
  #10  
Old 06-18-2009, 04:23 PM
NBVC's Avatar
NBVC NBVC is offline
Forum Guru
 
Join Date: 06 Dec 2006
Location: Mississauga, CANADA
MS Office Version:2003 & 2007
Posts: 18,489
NBVC has a brilliant future NBVC has a brilliant future NBVC has a brilliant future NBVC has a brilliant future NBVC has a brilliant future NBVC has a brilliant future NBVC has a brilliant future NBVC has a brilliant future NBVC has a brilliant future NBVC has a brilliant future NBVC has a brilliant future
Re: What's in Your Personal.xls?

Mine are mostly specific to my workplace, like changing Csv files to a nicely Formatted BOM form.. or actually consolidating quantities in CSV files to BOM's, etc..

But here is a simple one that I am sure people have already access to, I use to delete blank rows...

Code:
Sub DeleteBlankRows()


' Deletes the entire row within the selection if the ENTIRE row contains no data.
' Revised March 14, 2007 - added For/Next loop to ensure "empty appearing" cells are cleared.

On Error Resume Next

Dim i As Long
Dim c As Range, OrigRange As Range

    
With Application
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
        
        
    ' Set original selection for later use
    Set OrigRange = Selection
    
' clear contents of seemingly empty cells that are really not empty

' This version formats text as general
    With ActiveSheet
        .UsedRange.Value = Evaluate("IF(ROW(" & .UsedRange.Address & "),CLEAN(" & .UsedRange.Address & "))")
    End With
            
' This version keeps cell formats as text
'    Selection.SpecialCells(xlCellTypeConstants, 23).Select
'
'    For Each c In Selection
'         If Len(c) = 0 Then c.ClearContents
'    Next c
      
    'Delete blank rows starting at bottom of selection
    For i = OrigRange.Rows.Count To 1 Step -1
        If WorksheetFunction.CountA(OrigRange.Rows(i)) = 0 Then
            OrigRange.Rows(i).EntireRow.Delete
        End If
    Next i
    
    Range("A1").Select

    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
End With

End Sub
__________________
Where there is a will there are many ways. Pick One!

Please read the Forum Rules

If you are happy with the results, please add to my reputation by clicking the icon next to the Post # in the bar above my avatar (picture) in this post.

Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.
Reply With Quote
  #11  
Old 06-18-2009, 05:46 PM
DonkeyOte's Avatar
DonkeyOte DonkeyOte is offline
Forum Guru
 
Join Date: 22 Oct 2008
Location: Suffolk, UK
MS Office Version:2002 & 2007
Posts: 13,643
DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute
Re: What's in Your Personal.xls?

I just wanted to say I don't use a Personal.xls... adding no value to the thread per se just thought I should point out how odd I am... and wondered if anyone else out there like me... I do have a libary of exported modules (.bas) which I import to files as and when but that's about it (along with some old .xla's)...

Interesting thread... cheers shg.
Reply With Quote
  #12  
Old 06-18-2009, 05:57 PM
shg's Avatar
shg shg is offline
Forum Guru
 
Join Date: 20 Jun 2007
Location: The Great State of Texas
MS Office Version:2003, 2007
Posts: 18,450
shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay
Re: What's in Your Personal.xls?

You're in good company -- Andy Pope doesn't use one.
__________________
Entia non sunt multiplicanda sine necessitate.
Reply With Quote
  #13  
Old 06-18-2009, 06:00 PM
DonkeyOte's Avatar
DonkeyOte DonkeyOte is offline
Forum Guru
 
Join Date: 22 Oct 2008
Location: Suffolk, UK
MS Office Version:2002 & 2007
Posts: 13,643
DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute
Re: What's in Your Personal.xls?

Maybe it's just because we're both "Essex Boys" ...
(I might live in Suffolk in the UK but I'm a born & bred Essex Boy... note to non-Brits - that's not a good thing in terms of sterotypes...)
Reply With Quote
  #14  
Old 06-19-2009, 07:39 AM
StephenR StephenR is offline
Forum Guru
 
Join Date: 26 Aug 2007
Location: London
Posts: 2,210
StephenR is very confident of their ability StephenR is very confident of their ability StephenR is very confident of their ability StephenR is very confident of their ability StephenR is very confident of their ability
Re: What's in Your Personal.xls?

I had a friend in Essex who was continually at pains to point out that he lived in the posh bit (which was virtually Suffolk).

I don't claim authorship of any of these except the really short ones, some of which could probably be done with keyboard shortcuts but originate from when I first discovered VBA and wanted to do everything with macros.
Code:
Sub Filenames()
    
Dim sName As String, vNames(), sType As String, sPath As String, i As Long

' Change folder to suit
sPath = "C:\Documents and Settings\StephenR\"
ChDrive sPath
ChDir sPath

sType = "*.xls"
sName = Dir(sType)
Do Until sName = ""
    i = i + 1
    ReDim Preserve vNames(1 To i)
    vNames(i) = sName
    sName = Dir
Loop
If i = 0 Then
    MsgBox "No files found"
Else
    For i = 1 To UBound(vNames)
        Cells(i, 1) = vNames(i)
      ' To remove .xls suffix
      ' Cells(i, 1) = Left(vNames(i), Len(vNames(i)) - 4)
    Next i
End If
            
End Sub
Code:
Sub LoopThroughFolder()

Dim nCount As Long, wbResults As Workbook, wbCodeBook As Workbook

With Application
    .ScreenUpdating = False: .DisplayAlerts = False: .EnableEvents = False
End With
On Error Resume Next
Set wbCodeBook = ThisWorkbook

With Application.FileSearch
    .NewSearch
  ' Change path to suit
    .LookIn = "C:\MyDocuments\TestResults"
    .FileType = msoFileTypeExcelWorkbooks
  ' .Filename = "Book*.xls"
  ' Workbooks in folder
    If .Execute > 0 Then
      ' Loop through all
        For nCount = 1 To .FoundFiles.Count
            Set wbResults = Workbooks.Open(Filename:=.FoundFiles(nCount), UpdateLinks:=0)
          ' do whatever
            wbResults.Close SaveChanges:=True
        Next nCount
    End If
End With

On Error GoTo 0
With Application
    .ScreenUpdating = True: .DisplayAlerts = True: .EnableEvents = True
End With

End Sub
Code:
Sub FindTemplate1()
  
Dim rFind As Range, sFind As String, sAddress As String
 
sFind = "Word"

With Sheet1.Columns(1)
    Set rFind = .Find(What:=sFind, After:=rFind, LookIn:=xlFormulas, _
                          LookAt:=xlPart, SearchOrder:=xlByRows, _
                          SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If Not rFind Is Nothing Then
        sAddress = rFind.Address
        Do
          ' do whatever
            Set rFind = .FindNext(rFind)
         Loop While rFind.Address <> sAddress
       ' Loop Until rFind Is Nothing - use this if found values are being deleted or moved outside rFind
    End If
End With
     
End Sub
Code:
Sub VerticalCentre()
    Selection.VerticalAlignment = xlCenter
End Sub

Sub Wrap()
    Selection.WrapText = Not Selection.WrapText
End Sub

Sub RemoveFilter()
    ActiveSheet.AutoFilterMode = False
End Sub

Sub NumbComma()
    Selection.NumberFormat = "#,##0"
End Sub

Sub NoColour()
    Selection.Interior.ColorIndex = xlNone
End Sub

Sub CentreSel()
    Selection.HorizontalAlignment = xlCenterAcrossSelection
End Sub

Sub TxtBox()
    ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 575.25, 42.75, 250#, 200).Select
End Sub

Sub ClearHyperlinks()
    Dim rng As Range
    For Each rng In Selection
        rng.Hyperlinks.Delete
    Next rng
End Sub

Sub UnhideHiddenSheets()
    Dim ws As Worksheet
    For Each ws In Worksheets
        If ws.Visible = False Then
            ws.Visible = True
        End If
    Next ws
End Sub

Sub CorrectBlank()
    ' Corrects Value error caused by empty cell regarded as text
    Dim rng As Range
    For Each rng In Selection
        If Len(rng) = 0 Then
            rng.Value = rng.Value
        End If
    Next rng
End Sub

Sub BevelButton()
    ActiveSheet.Shapes.AddShape(msoShapeBevel, 500#, 100, 93#, 34.5).Select
    With Selection
        .Characters.Text = "PRESS ME"
        .Font.Bold = True
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .ShapeRange.Fill.ForeColor.SchemeColor = 46
    End With
End Sub

Sub DelimitSpace()
    On Error GoTo errline
    Range(Selection, Selection.End(xlDown)).TextToColumns Destination:=Selection(1, 1), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, Comma:=False, _
        Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
    Exit Sub
errline:
    MsgBox "No data selected"
End Sub

Sub RandomNumbers()
    Dim rng As Range, c As Long
    Application.ScreenUpdating = False
    On Error GoTo errline
    For Each rng In Selection
        rng.Value = Int(Rnd() * 100)
    Next rng
    With Selection
        For c = 1 To .Columns.Count
            .Cells(1, c) = "Heading " & c
        Next c
        .Cells.HorizontalAlignment = xlRight
    End With
    Application.ScreenUpdating = True
    Exit Sub
errline:
    MsgBox "Invalid selection"
End Sub
Reply With Quote
  #15  
Old 06-19-2009, 08:12 AM
DonkeyOte's Avatar
DonkeyOte DonkeyOte is offline
Forum Guru
 
Join Date: 22 Oct 2008
Location: Suffolk, UK
MS Office Version:2002 & 2007
Posts: 13,643
DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute DonkeyOte has a reputation beyond repute
Re: What's in Your Personal.xls?

Quote:
I had a friend in Essex who was continually at pains to point out that he lived in the posh bit (which was virtually Suffolk).
Are we friends but don't know we're friends ??? Me too...
(If he was indeed a he, and he continuously referred to his hometown as the oldest recorded town & former Roman Capital of Britain (Camulodunum) and former home to Damon Albarn of Blur then there's a good chance we know each other...)

Promise I won't darken the thread further unless I have something worthy to add. Sorry.
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump