+ Reply to Thread
Page 3 of 3 FirstFirst 123
Results 31 to 42 of 42
  1. #31
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    Location
    Leeds, UK
    MS-Off Ver
    2003 (work), 2007 & 2010 (home)
    Posts
    3,517

    Re: What's in Your Personal.xls?

    I agree add-ins are probably better and I use those when I've written something to share with others but if it's just for me I use my personal.xls and keep a copy in my Google Docs so I can download it wherever I want.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    If you haven't already please take some time to read the Forum Rules.

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  2. #32
    Forum Guru
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2003
    Posts
    2,286

    Re: What's in Your Personal.xls?

    - a toggle between manual and automatic calculation
    I have this, it's called 'dumbass mode button', when I click it my statusbar shows 'warning, dumbas mode enabled'
    CC

    If you like a post, please rate with the scales icon (top right).
    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  3. #33
    Forum Guru
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2003
    Posts
    2,286

    Re: What's in Your Personal.xls?

    Dom, I'd really appreciate a look at your compare spreadsheets code, if you don't mind?
    CC

    If you like a post, please rate with the scales icon (top right).
    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  4. #34
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    MS 2007
    Posts
    4,972

    Re: What's in Your Personal.xls?

    Charlie, I liked your Compare function. It will definitely come in handy when validating huge spreadsheets with complex formulas. Thanks!
    ChemistB
    My 2¢

    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

  5. #35
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    Location
    Leeds, UK
    MS-Off Ver
    2003 (work), 2007 & 2010 (home)
    Posts
    3,517

    Re: What's in Your Personal.xls?

    You're welcome to it although it's probably not quite what you're thinking of from my post. It's just some code that I use to compare the output of SAP reports that we've run pre and post applying patches to see if they've had any effect on the output of the reports.

    It highlights the differences and sticks hyperlinks to the first 255 in the first couple of rows of the second worksheet (I work on the fact that if there's more than 255 differences we've got real problems )

    I wrote this quite a long time ago so it could be greatly improved.

    Code:
    Sub CompareSheets()
        
        Dim strPreSheet As String, strPostSheet As String
        Dim wsPresheet As Worksheet, wsPostsheet As Worksheet
        Dim rngLoopRange As Range, lngNErrors As Long
        Dim strDifferentCells(256) As String, strOutput As String, C As Long
        
        strPreSheet = InputBox("Enter the name of the first worksheet")
        strPostSheet = InputBox("Enter the name of the second (output) worksheet")
        
        If strPreSheet = "" Or strPostSheet = "" Then
            MsgBox "Procedure cancelled", vbCritical
            Exit Sub
        End If
        
        Set wsPresheet = Sheets(strPreSheet)
        Set wsPostsheet = Sheets(strPostSheet)
     
        If wsPresheet.UsedRange.Rows.Count <> wsPostsheet.UsedRange.Rows.Count Then
            MsgBox "Different number of rows in worksheets", vbCritical
            Exit Sub
        End If
        
        If wsPresheet.UsedRange.Columns.Count <> wsPostsheet.UsedRange.Columns.Count Then
            MsgBox "Different number of columns in worksheets", vbCritical
            Exit Sub
        End If
    
        lngNErrors = 0
        
        For Each rngLoopRange In wsPostsheet.UsedRange
            
            If rngLoopRange.Value <> wsPresheet.Range(rngLoopRange.Address).Value Then
                
                rngLoopRange.Interior.ColorIndex = 3
                
                If (lngNErrors < 256) Then
                
                    strDifferentCells(lngNErrors) = rngLoopRange.Offset(2, 0).Address
                
                End If
                
                lngNErrors = lngNErrors + 1
            
            End If
        
        Next rngLoopRange
        
        If (lngNErrors > 0) Then
        
            With wsPostsheet
        
                .Rows("1:2").Insert Shift:=xlDown
                .Range("A1") = "Found " & lngNErrors & " differences."
        
                For C = 0 To lngNErrors - 1
            
                    If C > 255 Then Exit For
            
                    .Hyperlinks.Add Anchor:=.Range("A2").Offset(0, C), Address:="", SubAddress:= _
                        strDifferentCells(C), TextToDisplay:=strDifferentCells(C)
    
                Next C
                
            End With
        
        Else
        
            MsgBox "No errors found!!!"
        
        End If
        
    End Sub

    Dom
    Last edited by Domski; 08-05-2010 at 11:45 AM.
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    If you haven't already please take some time to read the Forum Rules.

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  6. #36
    Forum Guru
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2003
    Posts
    2,286

    Re: What's in Your Personal.xls?

    Normally I can't be bothered with tidying up functional code - even it could benefit from it, but this:
    Code:
    strPreSheet = InputBox("Enter the name of the first worksheet")
        strPostSheet = InputBox("Enter the name of the second (output) worksheet")
    Made me write this, general tool for picking either any worksheet in the active workbook, or any open workbook - something I've written individual versions of too many times... not any more!

    Code:
    Function Picker(iPickType As Integer, Optional sMessage As String, Optional sCaption As String) As String
    'ipicktypes:
    '1 = worksheets in active book
    '2 = open workbooks
    Dim wb As Workbook
    Dim ws As Worksheet
    With fPicker
        .Caption = sCaption
        .Label1.Caption = sMessage
        .ComboBox1.Clear
        Select Case iPickType
        Case 1
            For Each ws In ActiveWorkbook.Worksheets
                .ComboBox1.AddItem (ws.name)
            Next ws
        Case 2
            For Each wb In Workbooks
                If wb.name <> "PERSONAL.XLS" Then
                    .ComboBox1.AddItem (wb.name)
                End If
            Next wb
        End Select
        .Show
        Picker = .ComboBox1.Value
    End With
    End Function
    Supported (obviously?) by a very simple userform with one label, one combobox and two buttons, one (cancel) clears the combobox entry before hiding, (ok) just hides the userform.

    If Picker returns "" then consider it a cancel in either case...

    Not sure it was worth the endeavour, but I needed a break, work's killing me today!
    CC

    If you like a post, please rate with the scales icon (top right).
    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  7. #37
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    Location
    Leeds, UK
    MS-Off Ver
    2003 (work), 2007 & 2010 (home)
    Posts
    3,517

    Re: What's in Your Personal.xls?

    FWIW I put together an example of this working for this post...

    http://www.excelforum.com/excel-prog...o-compare.html

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    If you haven't already please take some time to read the Forum Rules.

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  8. #38
    Valued Forum Contributor snb's Avatar
    Join Date
    05-09-2010
    Location
    Europe
    MS-Off Ver
    Excel 2003
    Posts
    4,927

    Re: What's in Your Personal.xls?

    I couldn't resist...

    Code:
    Function Picker(iPickType As Integer, Optional sMessage As String, Optional sCaption As String) As String
      With fPicker
        .Caption = "Select Work" & Choose(iPickType, "sheet", "book")
        .Label1.Caption = .Caption
        .ComboBox1.ListIndex = -1
          For Each wb In Choose(iPickType, ActiveWorkbook.Worksheets, Workbooks)
            c01 = c01 & vbCr & wb.Name
          Next
          .ComboBox1.List = Split(Mid(c01, 2), vbCr)
          .Show
          Picker = IIf(.ComboBox1.Value = "", "No work" & Choose(iPickType, "sheet", "book"), "Work" & Choose(iPickType, "sheet ", "book ") & .ComboBox1.Value) & " selected"
        End With
    End Function
    
    Sub Book_Picker()
        MsgBox Picker(2)
    End Sub
    
    Sub Sheet_Picker()
        MsgBox Picker(1)
    End Sub

  9. #39
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: What's in Your Personal.xls?

    Here's another alternative
    Attached Files Attached Files
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  10. #40
    Forum Guru
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2003
    Posts
    2,286

    Re: What's in Your Personal.xls?

    I couldn't resist...
    :D Know the feeling

    I like the use of choose (all of them), but I'm not a fan of iif. (spit).

    Why add the elements to a string then split the string into the box rather than add the items straight into the box? (I don't mean to make any judgement either way, just curious).
    CC

    If you like a post, please rate with the scales icon (top right).
    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  11. #41
    Valued Forum Contributor snb's Avatar
    Join Date
    05-09-2010
    Location
    Europe
    MS-Off Ver
    Excel 2003
    Posts
    4,927

    Re: What's in Your Personal.xls?

    Why add the elements to a string then split the string into the box rather than add the items straight into the box? (I don't mean to make any judgement either way, just curious).
    with .List you don't need 'clear'
    .additem is noticebly slow
    .list is designed for assigning multiple items to a listbox/combobox at a time

    you could also use an array, but I like the simplicity of split (no need to dim, redim, redimpreserve etc.)

  12. #42
    Valued Forum Contributor alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Lake County, Illinois
    MS-Off Ver
    MS Office 2007 Pro
    Posts
    1,047

    Re: What's in Your Personal.xls?

    Here's one that I have passed on to many people.

    Code:
    Sub DeleteDuplicateRows()
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' DeleteDuplicateRows
    ' This will delete duplicate records, based on the Active Column. That is,
    ' if the same value is found more than once in the Active Column, all but
    ' the first (lowest row number) will be deleted.
    '
    ' To run the macro, select the entire column you wish to scan for
    ' duplicates, and run this procedure.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Dim r As Long
    Dim n As Long
    Dim V As Variant
    Dim rng As Range
    
    On Error GoTo EndMacro
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    
    Set rng = Application.Intersect(ActiveSheet.UsedRange, _
                        ActiveSheet.Columns(ActiveCell.Column))
    
    Application.StatusBar = "Processing Row: " & Format(rng.Row, "#,##0")
    
    n = 0
    For r = rng.Rows.Count To 2 Step -1
    If r Mod 500 = 0 Then
        Application.StatusBar = "Processing Row: " & Format(r, "#,##0")
    End If
    
    V = rng.Cells(r, 1).Value
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Note that COUNTIF works oddly with a Variant that is equal to vbNullString.
    ' Rather than pass in the variant, you need to pass in vbNullString explicitly.
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    If V = vbNullString Then
        If Application.WorksheetFunction.CountIf(rng.Columns(1), vbNullString) > 1 Then
            rng.Rows(r).EntireRow.Delete
            n = n + 1
        End If
    Else
        If Application.WorksheetFunction.CountIf(rng.Columns(1), V) > 1 Then
            rng.Rows(r).EntireRow.Delete
            n = n + 1
        End If
    End If
    Next r
    
    EndMacro:
    
    Application.StatusBar = False
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    MsgBox "Duplicate Rows Deleted: " & CStr(n)
    
    
    End Sub

Thread Information

Users Browsing this Thread

There are currently 3 users browsing this thread. (0 members and 3 guests)

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.2.0