Re: Filter rows AND columns in pivot table
Normal politeness :smile:
Re: Filter rows AND columns in pivot table
Normal politeness :smile:
Re: Filter rows AND columns in pivot table
Thank you Carim for the pointer.
I ended up going with a simple macro and an Active-X button to hide/show the rows/columns instead.
I'll append an example of the sheet layout I have in my pivot table.
I was asked to help a colleague with this problem.
Basically, I would like to filter the results so that all rows from column B onward (note that there are approximately 100-150 columns)
that only contain zeroes are excluded/hidden as well as all rows where all row values from column B are zeroes are excluded/hidden.
Note that this workbook does not contain any macros, so if the solution required a macro, I could write it, but I'm not 100%
certain the colleague would accept that sort of change to the workbook (what with the requirement for a trusted location etc)
In the attached example, I want all the rows in green to be excluded (since all the columns contain zero) as well as all the yellow columns (since all the rows contain zero).
[ATTACH=CONFIG]71479[/ATTACH]
Re: Sort produce unexpected results
Thanks Kenneth, but I think it's easier than that. It occurred to me on the way home on the tube, that, MAYBE, it's to do with me having a Swedish Windows installation.
If we ignore the first characters (V's and W's), then the second ones are all sorted correctly. Now Swedish DOES have the character W, but maybe not in MS's world ?
On the assumption that my idea is correct, is there a way of specifying the sort character string to Excel ?
Just tried an experiment. Exported the sheet as a csv file, then opened it and sorted it on the relevant column; same results. Strange .....
After some searching, I found this link http://www.mrexcel.com/forum/e…al-sorting-mixes-v-w.html
which talks about the same thing. In the end, I followed the suggestion proposed by Gerald Higgins which works, but it seems strange that
such a workaround should be needed for something so simple.
I realize the title will result in people thinking "aha, he hasn't got a clue what he's doing", but let's see if you still think this after I explain my problem.
One of my sheets contains 3 relevant columns; A is empty, then comes B with international country names, then C with a 2-character international ISO code, then D with a numeric value 1-3 indicating
whether the country is a low (1) to high (3) risk country (money laundering).
I have the following sort code in my macro:-
Range("C65536").End(xlUp).Select
nr_rows = ActiveCell.row
ActiveWorkbook.Worksheets("Land").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Land").Sort.SortFields.Add Key:= _
ActiveWorkbook.Worksheets("Land").Range("C1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Land").Sort
.SetRange Range("B1:D" & nr_rows)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Display More
I have also tried sorting column C MANUALLY using Excel's sort option. In both cases, I'm receiving the following results at the bottom of the list
QuoteDisplay More[tr]
[TABLE="width: 487"][td]
HOLY SEE (VATICAN CITY STATE)
[/td][td]
VA
[/td][/tr]
[tr]
[td]
SAINT VINCENT AND THE GRENADINES
[/td][td]
VC
[/td][/tr]
[tr]
[td]
VENEZUELA, BOLIVARIAN REPUBLIC OF
[/td][td]
VE
[/td][/tr]
[tr]
[td]
WALLIS AND FUTUNA
[/td][td]
WF
[/td][/tr]
[tr]
[td]
VIRGIN ISLANDS, BRITISH
[/td][td]
VG
[/td][/tr]
[tr]
[td]
VIRGIN ISLANDS, U.S.
[/td][td]
VI
[/td][/tr]
[tr]
[td]
VIETNAM
[/td][td]
VN
[/td][/tr]
[tr]
[td]
SAMOA
[/td][td]
WS
[/td][/tr]
[tr]
[td]
VANUATU
[/td][td]
VU
[/td][/tr]
[tr]
[td]
KOSOVO not official ISO code
[/td][td]
XK
[/td][/tr]
[tr]
[td]
YEMEN
[/td][td]
YE
[/td][/tr]
[tr]
[td]
MAYOTTE
[/td][td]
YT
[/td][/tr]
[tr]
[td]
SOUTH AFRICA
[/td][td]
ZA
[/td][/tr]
[tr]
[td]
ZAMBIA
[/td][td]
ZM
[/td][/tr]
[tr]
[td]
ZIMBABWE
[/td][td]
ZW
[/td][/tr]
[/TABLE]
Now, whichever way I look at it, VU (Vanatua) SHOULD come before WS (Samoa) and Wallis and Futuna shouldn't come as high up as it does either.
Can anyone suggest what might be wrong ?
Re: Combo Box in user form to select a file from all open files to use in a macro.
Not sure if this is another (possible) answer to your problem. I have written a workbook that fires up a userform. This form automatically "fetches" in all xlsx files and creates/populates a combo box with
their first letter (for example, one option would be the A-E filenames, another F-J etc etc).
You then select the combo box and a listbox is populated with the files matching the starting letters. You select the files that are of interest, click the OK button and whatever you want
done can be performed based on the selected files.
.... or is that overkill for what you want ?
Re: Prevent ComboBox Change Event Firing On Save
Fair enough, but shouldn't the topic title be changed to "Prevent combobox change event firing on Save as" (since that was the whole point of my append)
Re: ComboBox Change Event Fires On Save As
That's fine inasmuch as it's a programming workaround, but it doesn't (to me) explain why I need to code this. (Or why the Save as button causes this behaviour but the Save button doesn't, and from there, we're back to my original topic title)
Re: Change combo event for Save as but not for Save
Sorry Dave, I thought my title was explicit enough.
Let me phrase it this way. On reviewing the VBA code, I can't see anything that would cause the combobox event to fire programmatically, thereof my confusion. Here is the combobox event code
Private Sub cboVäljMall_Change()
'
' Come here when the combo box is changed. This ALSO happens
' when the user does a Save as (not sure why though)
MsgBox "We are in cboVäljMall_Change"
'
With wsUnderlag
If .Range("MallRubrikerStart").Offset(cboVäljMall.ListIndex, 1) = "Unlocked" Then
Range("Kundföretag").Select
Range("MånAvgRedoNr").Locked = False
Range("ÅrsAvgSäljS").Locked = False
Range("AvgAviSäljS").Locked = False
Range("DebetKr").Locked = False
Range("DebetProc").Locked = False
Range("KreditKr").Locked = False
Range("KreditProc").Locked = False
Range("UtlKr").Locked = False
Range("UtlProc").Locked = False
Else
Range("Kundföretag").Select
Range("MånAvgRedoNr").Locked = False
Range("ÅrsAvgSäljS").Locked = False
Range("AvgAviSäljS").Locked = False
Range("DebetKr").Locked = False
Range("DebetProc").Locked = False
Range("KreditKr").Locked = False
Range("KreditProc").Locked = False
Range("UtlKr").Locked = False
Range("UtlProc").Locked = False
Range("MånAvgRedoNr") = .Range("AvgiftsmallarStart").Offset(1, cboVäljMall.ListIndex * 2)
Range("ÅrsAvgSäljS") = .Range("AvgiftsmallarStart").Offset(2, cboVäljMall.ListIndex * 2)
Range("AvgAviSäljS") = .Range("AvgiftsmallarStart").Offset(3, cboVäljMall.ListIndex * 2)
Range("DebetKr") = .Range("AvgiftsmallarStart").Offset(5, cboVäljMall.ListIndex * 2)
Range("DebetProc") = .Range("AvgiftsmallarStart").Offset(5, cboVäljMall.ListIndex * 2 + 1)
Range("KreditKr") = .Range("AvgiftsmallarStart").Offset(6, cboVäljMall.ListIndex * 2)
Range("KreditProc") = .Range("AvgiftsmallarStart").Offset(6, cboVäljMall.ListIndex * 2 + 1)
Range("UtlKr") = .Range("AvgiftsmallarStart").Offset(7, cboVäljMall.ListIndex * 2)
Range("UtlProc") = .Range("AvgiftsmallarStart").Offset(7, cboVäljMall.ListIndex * 2 + 1)
End If
End If
End With
bolSave = False ' If we come into this sub again, we ARE changing the combo box
End Sub
Display More
All I can say is this. If I choose a combobox option, I get the MSGBOX at the top of the code. If I do a manual Save I don't get the message (ie, I don't run through the combobox event). If I select Save as I get the msgbox.
Is there some other setting/generalized variable that I'm unaware of ? (And by generalized variable, I mean some "esoteric" Excel workbook variable that I don't know about based on my limited knowledge)
I've programmed my way around this, but I'm curious as to whether anyone can explain what's going on and whether there's a simple setting that might negate the "problem".
Basically, my worksheet has a combo defined. If I do a Save (manually), the change combo event doesn't kick in. If I do a Save as (again, manually) it does.
Re: Change Numeric Constants In Column To Zeros
Thanks Dave - your comment pointed me in the right direction (the data contained calculations rather than straight-forward data that I was expecting).
QuoteBTW. Whats with the 2 "char" in rows address???
My bad thinking
Re: Change Numeric Constants In Column To Zeros
Append removed (mea culpa and stupidity)
Re: Change Numeric Constants In Column To Zeros
I hope this can be considered a follow-on question to the previous rather than a new topic.
I want to do the same thing as above, but for a range of cells (B2:M7). I tried the following
but that failed, then I tried
Dim alpha(12) As String, char As String, row_range As String
Dim i As Integer
alpha(1) = "B"
alpha(2) = "C"
alpha(3) = "D"
alpha(4) = "E"
alpha(5) = "F"
alpha(6) = "G"
alpha(7) = "H"
alpha(8) = "I"
alpha(9) = "J"
alpha(10) = "K"
alpha(11) = "L"
alpha(12) = "M"
For i = 1 To 12
char = alpha(i)
row_range = char & "2:" & char & "7"
ActiveSheet.range(row_range).SpecialCells(xlCellTypeConstants, xlNumbers) = 0
Next i
Display More
which worked for column B, but failed with a 1004 on column C.
What is the correct way of doing this ?
Re: Change Numeric Constants In Column To Zeros
Thanks for the answer. I had to change the B:B to something like B:X (or similar) since I wanted to change ALL the cells in the sheet (apart from the superfluous rows on the next sheet).
Any explanation as to why the original code (which I googled somewhere) would have behaved as it did and why your code doesn't. (I assume it has nothing do do with the fact that your code was in its own SUB ?)
I have the following code
Call LastCell_Example(LastCell)
lastrow = Cells(Rows.Count, "B").End(xlUp).row
Set Datarange = ActiveSheet.Range("B1:" & LastCell)
' Set to 0 all cells that contain constants, but ONLY those that are numeric
Datarange.SpecialCells(xlCellTypeConstants, xlNumbers) = 0
lastcell_example contains
Dim rng As Range
' Use all cells on the sheet
Set rng = Sheets("Courtage").Cells
' Find the last cell
LastCell = Last(3, rng)
' Select from A1 till the last cell in Rng
With rng.Parent
.Select
.Range("A1", LastCell).Select
End With
Display More
When I run the code above, I don't understand the fact that the first rows in the sheet AFTER "Courtage" are also being changed to zero.
Obviously, I'm not limiting my datarange correctly, but could someone explain what I need to do to limit the changed data to ONLY the current sheet.
Re: Updating Distributed VBA Macro Code
Thank you. Unfortunately, it's difficult sometimes to explain exactly what you're trying to do, without getting bogged down in extraneous explanations.
I've never used addins before, and reading up on them, I got the impression that they were the way to maintain centralized VBA code (that I can change), rather than each user having their own workbook with (possibly) outdated copies of the "same" (centralized) VBA code. (Bit like the fact that as soon as you start Firefox, if it's been updated at mozilla.org, your local code is updated automatically)
My users' scenario are 2.
Note that in item 1, the user doesn't have to press any buttons or do anything to get the data passed as the parm into a sheet.
I want to try and achieve exactly this, but somehow or other have the workbook run external code that is placed and maintained centrally. Ideally (?), when the (C-drive) workbook is called via item 1, it will recognize that it has been passed a string parm and will run VBA code in a workbook on a network drive. As to whether the network drive code is defined as an addin or not, that's beyond my competence.
Re: Addins
Thank you both for answering. Let's see if I can answer your suggestions as I understand them. At the moment, imagine my application is started from a DOS window. I pass it the name of the workbook I want to open, as well as a long parameter string. The open event in the workbook takes the long string and runs a function that analyses the string and populates a sheet with data as a result. This is working fine at the moment. My problem is that this workbook is copied to each user's private drive (obviously including any vba code). As a result, if thecentral workbook VBA code is updated, the users never see it (since they're now accessing their own private copy).
To reply to your suggestions.
Tony. I don't want the user to have to press any button after the workbook is loaded. Is there a possibility to start excel, pass the name of the workbook as a parm and the name of some function to run ? (This doesn't get me past the updated VBA code though)
Simon. Yes _ I want the code to run on opening the workbook (which, as mentioned, it's doing).
Like I say, what happens if the central VBA code is updated though ?
When submitting a new topic, you are shown a list of possible suggestions that might already have answered your question. Running Firefox, this is then opened in a new window, but (for me at least) without the back/forward buttons. If I then review one of the suggestions, I can't see how I'm supposed to return to review another one instead (all I have is the close window button).
Am I missing something obvious ?
Addins
Wasn't sure how to specify a title for this topic and didn't want to second-guess where the error was - thereof the concise title.
Am trying to get my head round addins and how to use them. The background is as follows. I have a workbook (call it X) on a network drive. When users run an application, this workbook is copied to a drive the user owns (if not already there) and the next available sheet is populated with data via VBA code. The actual code that populates the sheet is quite complicated, so I wanted to be able to update the user's workbook with updated VBA code as required (without them having to re-copy the workbook from the network dive). I read this site's description on addins and got the impression that that was what I was after. I therefore created the following
I then added the xla addin to the xls file on the network drive.
My problem is that when I then open Excel (empty) , the open workbook code from the addin is run automatically (ie, the X application code is run). If instead I open Excel with parameters using X, it seems that I first run the xla code, and then, once this has run, I get the standard question "Do you want to enable/disable macros" and the application code is run again.
Long and the short - is there a better way to ensure distributed VBA code can be updated automatically from a central network drive when that VBA code is updated ?
Assume the follownig:-
I'm wondering if there is a way to update the user's C-drive VBA code with some centralised VBA code when required. I've written code that can check if a file has been changed compared to the last time it was read in, so that shouldn't be a problem, but I'm not sure if updating/replacing VBA code is doable, and if so, what would be the best way to "store" the updated VBA code (in an xls file, in some sort of simple external text file, ....)