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.
I have this, it's called 'dumbass mode button', when I click it my statusbar shows 'warning, dumbas mode enabled'- a toggle between manual and automatic calculation
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.
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.
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)
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.
Normally I can't be bothered with tidying up functional code - even it could benefit from it, but this:
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:strPreSheet = InputBox("Enter the name of the first worksheet") strPostSheet = InputBox("Enter the name of the second (output) worksheet")
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.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
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.
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.
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
Here's another alternative
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
:D Know the feelingI couldn't resist...
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.
with .List you don't need 'clear'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).
.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.)
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
There are currently 3 users browsing this thread. (0 members and 3 guests)
Bookmarks