Re: List OLAP cube page fields, multiple items selected
just tried it again and now I'm getting an out of stack space error
my pivot data has about 40,000 rows of data if that matters
Re: List OLAP cube page fields, multiple items selected
just tried it again and now I'm getting an out of stack space error
my pivot data has about 40,000 rows of data if that matters
Re: List OLAP cube page fields, multiple items selected
This is something I have been looking for as well but I get a 'Next without For' error when I try to run the code above. I also had to change :
to
Re: split address into address/city/province/postal
Thank you very much. I will try this tomorrow. I noticed the same thing about the missing cities. I grabbed some lists that I found on Wikipedia but obviously there are a lot more out there. I will keep searching. Thanks again
Re: split address into address/city/province/postal
forum.ozgrid.com/index.php?attachment/38559/
Here is the list of cities.
Re: split address into address/city/province/postal
I agree 100% Barb-b, unfortunately the data was supplied by a client. I already asked them to break it up but so far no luck. I will see about finding a city list.
I have a column containing addresses that I need to split into multiple columns.
I have borrowed some formulas from other posts that almost do what I need but I don't know how to modify it further to split out the city into column F. Column E is currently showing both the address and the city.
Current formulas:
B2 =LEN(A2)
C2 =SEARCH(" ON ",A2,1)
D2 =C2+3
E2 =LEFT(A2,C2-1) (is giving address plus city)
F2 = (I don;t know what to put here)
G2 =MID(A2,C2+1,2)
H2 =MID(A2,D2+1,B2-D2)
Note: I would prefer not to have to hard code the province abbreviation "ON" (for 'Ontario') as I have done in the C2 formula as some addresses will contain other abbreviations. The odd address will have the province spelled out 'Ontario' instead of ON, for example. however I clean those up with a search and replace first.
Data sample
82 Horsely Hill Dr Scarborough ON M1B 1W5
4-46 ADVANCED RD ETOBICOKE ON M8Z 2T4
25 Planchet Road Unit 4 Concord ON L4K 2C5
41 Castle Dr Barrie ON L4N 1P9
596 Oster Lane Concord ON L4K 2C1
125 Anne St S Barrie ON L4N 7B6
1 Laidlaw Blvd Unit 1 Markham ON L3P 1W5
1360 Birchmount Rd Scarborough ON M1P 2E3
155 Lynden Rd Brantford ON N3R 8A7
5245 Harvester Rd Burlington ON L7L 5L4
PO Box 696 Barrie ON L4M 4Y5
110 Hopkins St , Whitby,ON L1N 2B7
110 Anne St S Unit 15 Barrie ON L4N 2E3
9 WOODS AVENUE RR OMMEME ON K0L 2W0
3437 CRESCENT HARBOUR RD INNISFIL ON L9S 2Y7
240 Brock St Peterborough ON K9H 2P7
2565 Kingsway,Sudbury ,ON P3B 2G1
30 Lawson Cr. Rosseau ON P0C 1J0
see attached
Re: import multiple csv files with header record and addresses with carriage returns
works like a charm! THANK YOU!!
I have approx. 5000 csv files to import onto a single page.
They all have the same format.
When I open the files with excel the data parses properly but the titles don't with the result that the last column of data has no header. If you open one of the files you will see what I mean.
When I tried to record a macro of the import it did not work because there are carriage returns in the last column of data which causes the data to wrap around so the columns don't line up and I don't know how to get around that using the import tool.
The following code I found in another thread does much of what I want but needs adjusting as the records end up split over two rows so it needs to be adjusted.
Sub import_fresh_txt_files()
Dim myDir As String, fn As String, txt As String, size As Integer, x
myDir = "c:\test" '<- change to actual folder path
fn = Dir(myDir & "\*.csv") 'any file
Do While fn <> ""
txt = CreateObject("Scripting.FileSystemObject").OpenTextFile(myDir & "\" & fn).ReadAll
x = Application.Transpose(Split(txt, vbCrLf))
size = UBound(x, 1)
If Application.WorksheetFunction.CountIf(Range("a:a"), fn) = 0 Then
Sheets("RAWDATA").Range("A1000000").End(xlUp)(2, 2).Resize(size).Value = x 'may change range here
Sheets("RAWDATA").Range("B1000000").End(xlUp)(-size + 3, 0).Resize(size).Value = fn
Else 'nothing
End If
fn = Dir()
Loop
End Sub
Display More
Re: Import and parse csv files with extraneous commas?
Here's a couple forum.ozgrid.com/index.php?attachment/37833/forum.ozgrid.com/index.php?attachment/37834/
Note that I had to change the extension to txt to get them to upload.
I have a lot of csv files to import. When I double click on any one of them manually using explorer excel opens them perfectly. However, when I loop through the same files using a script that incorporates a parsing array I recorded with excel's import tool, any file where one of the 'columns' has extra commas in it excel recognizes them and splits the data for that row into additional columns. For example, one column is for 'company name' and many companies have commas in their name. Can anybody tell me if it possible in VB to have excel open the files the same way it does natively as opposed to the hard coded array method created by the import tool?
Re: Reset agent's status on a master list while looping through daily refresh list
Hi Bill, I've been able to determine that the initial size of the 'from' range determines the maximum number of 'new licence' records that can be generated. Subsequent loads/refreshes of the 'from' page with new data will not generate 'new licence' records. Instead it will generate 2 new rows for each new record and flag them as "new name" and "new agency" respectively. That's all I've been able to figure out so far.
Re: Reset agent's status on a master list while looping through daily refresh list
I'm getting some strange results when I run it with real data (about 4500 rows). Ex. new records are being added but on subsequent loads without 'new licence' and instead are showing up twice with 'new name' and 'new agency'. I tried to determine if it was the number of records that was causing the problem but if it is, I don't see where. I did notice the A2:F500 range you are using on the hidden sheet in conjunction with the user form/controls but it had no effect when I increased it. Should the number of records make a difference?
forum.ozgrid.com/index.php?attachment/36531/
Re: Reset agent's status on a master list while looping through daily refresh list
Thank you very,very much Bill. I'm just going through your code now but it looks to be exactly what I needed and a whole lot more. People like you make this such a special place. Domo arigato gozaimas!
[I tried to think of a more succinct thread title but I couldn't so I phrased it as a question; (How do I) reset an agent's status on a master list while looping through the refresh list]
I am creating a spreadsheet to track agents and where they are licensed. Each day I receive a file containing the names and licence numbers of all licensed agents including the name of the agency they are licensed at. Agents tend to move around and/or drop out of action for a while and then resurface at a different (or same) agency. My goal is to create a report detailing which agencies are gaining/shedding agents while detailing who moved where etc. The daily file I receive contains the following 4 columns on the FROM tab;
Col A = Lic#
Col B = AgentName
Col C = Agency
Col D = ReportDt
Which I use to update the master list on the TO tab containing;
Col A = Lic#
Col B = Agent
Col C = OrigAgency
Col D = DateAdded
Col E = Mode
Col F = Updated
Col G = CurrAgency
Col H = Status
Col I = EventDt
The logic for the updating is;
If Lic# does not exist on master list (TO tab);
1) Add Lic# to master list (create new row), along with the Agent’s name, Agency and ReportDt in Columns A,B,C,D, where;
A=Lic#, B=Agent, C=OrigAgency, D= DateAdded
2) Set Mode to “Licenced”. Column E
3) Copy ReportDt to “Updated”. Column F
4) Copy Agency to “CurrAgency”. Column G
5) Set Status to “NewLic”. Column H
6) Copy ReportDt to “EventDt”. Column I
If Lic# already exists on master list (TO tab);
1) Check if Status = NewLic, if yes, set Status = Confirmed, copy ReportDt to “EventDt”.
2) Check if Status = Dropped, if yes, set Status = ReLicenced, copy ReportDt to “EventDt”.
3) Check if Status = Moved, if yes, set Status = Confirmed, copy ReportDt to “EventDt”.
4) Check if Status = ReLicenced, if yes, set Status = Confirmed, copy ReportDt to “EventDt”.
5) Check if Agency name has changed, if yes, set Status = MOVED, copy ReportDt to “EventDt”.
If Lic# exists on master list but no longer appears on FROM tab;
1) Set Status to Dropped. Column F
2) Set Mode to Unlicensed. Column E.
The code below handles most of the above except agents who transfer agencies (see PART E). The first time an agent moves their status should be changed to Moved. The next time they are reported at that same agency their status should change to Confirmed. It gets a little more complicated when they stop working (become UnLicensed) and then start working again at a new agency. My current code flags them as Moved when it should be ReLicensed. With my current code once an agent is flagged Moved, they stay that way. I have tried using various AND and ELSE combinations unsuccessfully. I am a VBA hack and was only able to develop what I have so far with help from other Oz members but I have hit a wall again and would very much appreciate further assistance. (most recent post was ‘Combine two macros and consolidate changes between new data and master list’; http://www.ozgrid.com/forum/showthread.php?t=149738)
Sub Compare_FROM_TO()
Dim MyRnge, MyNewRnge As Variant
Dim MyCounter, i, x, MyRngeLstRw, MyNewRngeLstRw, MyNewRngeLstCln, MyRngeLstCln As Integer
MyRngeLstRw = Sheets("from").Range("A1").End(xlDown).row
MyRngeLstCln = Sheets("from").UsedRange.Columns.Count
MyNewRngeLstRw = Sheets("to").Range("A1").End(xlDown).row
MyNewRngeLstCln = 4
MyRnge = Sheets("from").Range(Cells(2, 1).Address, Cells(MyRngeLstRw, MyRngeLstCln).Address) '= daily refresh file
MyNewRnge = ActiveWorkbook.Sheets("to").Range(Cells(2, 1).Address, Cells(MyNewRngeLstRw, MyNewRngeLstCln).Address) '=master list
For i = 1 To UBound(MyRnge, 1)
MyCounter = 0
For x = 1 To UBound(MyNewRnge, 1)
'PART A Lic# exists in master list, so...
If MyNewRnge(x, 1) = MyRnge(i, 1) Then
Sheets("to").Range("A" & x).Offset(1, 4) = "Licenced" ' set mode in Col E
Sheets("to").Range("A" & x).Offset(1, 5) = Format(Sheets("from").Range("D" & i + 1), "mm/dd/yy") 'record date updated Col F
Sheets("to").Range("A" & x).Offset(1, 6) = Sheets("from").Range("C" & i + 1) 'copy agency name to CurrAgency >> Col G
'PART B If Lic# exists AND Status = "NewLic", change to "Confirmed" since Lic# is no longer new
If Sheets("to").Range("A" & x).Offset(1, 7) = "NewLic" Then
Sheets("to").Range("A" & x).Offset(1, 7) = "Confirmed" 'Col H
Sheets("to").Range("A" & x).Offset(1, 8) = Format(Sheets("from").Range("D" & i + 1), "mm/dd/yy") ' Col I
End If
'PART C If Lic# exists AND Status = "Dropped", change to "ReLicenced" since Lic# is back on list
If Sheets("to").Range("A" & x).Offset(1, 7) = "Dropped" Then
Sheets("to").Range("A" & x).Offset(1, 7) = "ReLicenced" 'Col H
Sheets("to").Range("A" & x).Offset(1, 8) = Format(Sheets("from").Range("D" & i + 1), "mm/dd/yy") 'Col I
End If
'PART D If Lic# exists AND CurrAgency Name = Agency Name on refresh file
If Sheets("to").Range("A" & x).Offset(1, 2) = Sheets("from").Range("C" & i + 1) Then '
'do nothing.
Else 'if names don't match;
Sheets("to").Range("A" & x).Offset(1, 7) = "Moved" 'set STATUS
Sheets("to").Range("A" & x).Offset(1, 8) = Format(Sheets("from").Range("D" & i + 1), "mm/dd/yy") 'record date of event
End If
'PART E If Status = Moved AND Event Date < Update date = Settled
If Sheets("to").Range("A" & x).Offset(1, 7) = "Moved" And Sheets("to").Range("A" & x).Offset(1, 8) < Sheets("to").Range("A" & x).Offset(1, 5) Then
Sheets("to").Range("A" & x).Offset(1, 7) = "Settled" 'using 'settled' for now so I tell it's working, will switch to 'Confirmed' when it's working
Else
End If
MyCounter = MyCounter + 1
End If
Next x
If MyCounter = 0 Then
'PART G Lic# not found on master list; add new rows
addrow = Sheets("to").Range("a1048576").End(xlUp).row + 1
Sheets("to").Cells(addrow, 1) = MyRnge(i, 1) 'copy Lic# Col A
Sheets("to").Cells(addrow, 2) = MyRnge(i, 2) 'Agent name Col B
Sheets("to").Cells(addrow, 3) = MyRnge(i, 3) 'Agency name Col C
Sheets("to").Cells(addrow, 4) = MyRnge(i, 4) 'Date Added Col D
Sheets("to").Cells(addrow, 5) = "Licenced" 'Set Mode Col E
Sheets("to").Cells(addrow, 7) = MyRnge(i, 3) 'CurrAgency Col G
Sheets("to").Cells(addrow, 8) = "NewLic" 'Status Col H
Sheets("to").Cells(addrow, 9) = Format(Sheets("from").Range("D" & i + 1), "mm/dd/yy") 'Col I
MyCounter = MyCounter + 1
Else
End If
Next i
For i = 1 To UBound(MyNewRnge, 1)
MyCounter = 0
For x = 1 To UBound(MyRnge, 1)
If MyRnge(x, 1) = MyNewRnge(i, 1) Then MyCounter = MyCounter + 1
Next x
If MyCounter = 0 Then
'PART H Lic# not found in daily refresh file('from' tab); therefore agent is no longer licensed
Sheets("to").Range("A" & i).Offset(1, 4) = "unLicenced" ' set mode
Sheets("to").Range("A" & i).Offset(1, 5) = "'" 'blank out report date (it will still appear in Event Date)
Sheets("to").Range("A" & i).Offset(1, 7) = "Dropped" '>> 'Dropped' in status column H
Sheets("to").Range("A" & i).Offset(1, 8) = Format(Sheets("from").Range("D2"), "mm/dd/yy") 'since lic# does not exist on From tabe there...
'...is no corresponding date to grab for that record so just use the date from the first record in the date column
MyCounter = MyCounter + 1
Else
End If
Next i
End Sub
Display More
I have attached a sample spreadsheet. Please click the 'Edit macro" to view the code. forum.ozgrid.com/index.php?attachment/36506/
Re: Run macro when double-clicking a sheet tab
Another too simple solution - just tie your macro to the 'before right-click' event. That way your users just have to right click ever so slightly above the tab to make it work. You could also tie it to the double-click event of course but that can be dangerous depending on what's in the cell they are clicking on. I suspect you may have thought of that but I just thought I'd throw it out there for anyone else following this thread.
Re: Run macro when double-clicking a sheet tab
I can relate to your frustration. My original goal was to make buttons that 'float' down the spreadsheet the way they do on some websites as you scroll down (which I actually find rather annoying now) but that was a verry complex solution so I settled for locking them to the top row and making them semi-translucent. At 5-6 lines of code and something that can be easily replicated&modified it's a winner. And it's still very user friendly imo as people naturally tend to hover their mouse near the top of the screen. Good luck though!
I do have one other suggestion for you though, since double clicking a tab currently selects/highlights the name of the tab; simply create a macro that fires on a change in the tab name (after capturing the name of the tab of course so you can cange it back at the end)
Re: Run macro when double-clicking a sheet tab
You could make a macro to create a small button or two at the top of the page in row one, then turn freeze panes on row one so the buttons are always visible no matter how many pages they scroll down. By tying this macro to the create new sheet event the buttons will appear on every new sheet in your workbook so they are always useable. I use this trick all the time and it works great. On many projects I give users a virtual dashboard of buttons to choose from in row 1 and they love it.
Here is an example of a simple macro to create two buttons at the top of the page.
Range("A2").Select
ActiveWindow.FreezePanes = True
ActiveSheet.Buttons.Add(290, 0, 10, 13).Select ‘290 =dist from left margin, 0 is how far down it appears and 10,13 are height/width
Selection.OnAction = "PivotPageDown" ‘ this links the button to the macro you want to run
Selection.Characters.Text = "<" ‘set display text for the button here
ActiveSheet.Buttons.Add(299, 0, 10, 13).Select
Selection.OnAction = "PivotPageUp"
Selection.Characters.Text = ">"
The result is two small buttons locked to the top of the screen that look like “<|>” and the user (in this case) can click one or the other to go forward or back through a pivot table one ‘page’ at a time. (using some wonderful code I found for linking a button to pivot filter control at http://www.contextures.com/excelfiles.html ) Of course you can tie the buttons to any macro you want just by inserting the name of it between the quotes after Selection.OnAction =
Re: Range changing error with pivot table
You don't mention if you're using a dynamic named range for the data in your pivot table but it may solve your problem. I don't recall the exact menu item to find it under but look for 'insert range' or 'inset named range' under the tools menu and create a new named range, give it whatever name you want and in the "refers to:" field enter the following;
replace DATA with the name of the tab your data is on. Then go to your pivot table options and change the data range to the name you selected for your dynamic range. If you can find it, right click on your pivot, select pivot table wizard and keep hitting the back button until you see it. The dynamic range should automatically adjust to any new columns you add/delete. Good luck.
Re: Combine two macros and collate changes between new data and master list
I'm getting an "application defined or object defined error" on the following line;
even though MyRngeLstCln is declared above it
Here is how the whole thinkg looks after I inserted your last post:
Dim MyRnge, MyNewRnge As Variant
Dim MyCounter, i, x, MyRngeLstRw, MyNewRngeLstRw, MyNewRngeLstCln, MyRngeLstCln As Integer
MyRngeLstRw = Sheets("from").Range("A1").End(xlDown).Row
MyRngeLstCln = Sheets("from").Range("A1").End(xlRight).Column
MyNewRngeLstRw = Sheets("To").Range("A1").End(xlDown).Row
MyNewRngeLstCln = Sheets("To").Range("A1").End(xlRight).Column
MyRnge = Sheets("from").Range(Cells(2, 1).Address, Cells(MyRngeLstRw, MyRngeLstCln).Address) '= fresh data to be merged
MyNewRnge = ActiveWorkbook.Sheets("to").Range(Cells(2, 1).Address, Cells(MyNewRngeLstRw, MyNewRngeLstCln).Address) ' = master list
For i = 1 To UBound(MyRnge, 1)
MyCounter = 0
For x = 1 To UBound(MyNewRnge, 1)
If MyNewRnge(x, 1) = MyRnge(i, 1) Then
'If Lic# matches, append agent+agency name >> 'to' sheet
Sheets("to").Range("A" & x).Offset(1, 4) = "onlist" '< Status
Sheets("to").Range("A" & x).Offset(1, 5) = Format(Date, "Mmmdd/yyyy")
Sheets("to").Range("A" & x).Offset(1, 6) = Sheets("from").Range("C" & i + 1)
'If agency name on 'to' page = agency name on 'from' page
If Sheets("to").Range("A" & x).Offset(1, 2) = Sheets("from").Range("C" & i + 1) Then
Else
Sheets("to").Range("A" & x).Offset(1, 4) = "switched" 'agent switched to new agency
Sheets("to").Range("A" & x).Offset(1, 5) = Format(Date, "Mmmdd/yyyy")
End If
MyCounter = MyCounter + 1
End If
Next x
If MyCounter = 0 Then
'Lic# was not found on 'to' sheet so add new rows and copy over new data
addrow = Sheets("to").Range("a65536").End(xlUp).Row + 1
Sheets("to").Cells(addrow, 1) = MyRnge(i, 1) 'copy lic# to A
Sheets("to").Cells(addrow, 2) = MyRnge(i, 2) 'agent name to B
Sheets("to").Cells(addrow, 3) = MyRnge(i, 3) 'agency name to C
Sheets("to").Cells(addrow, 4) = Format(Date, "Mmmdd/yyyy")
Sheets("to").Cells(addrow, 5) = "new to list"
MyCounter = MyCounter + 1
Else
End If
Next i
For i = 1 To UBound(MyNewRnge, 1)
MyCounter = 0
For x = 1 To UBound(MyRnge, 1)
If MyRnge(x, 1) = MyNewRnge(i, 1) Then MyCounter = MyCounter + 1
Next x
'Existing Lic# was not found in new data, therefore Lic# has dropped from service
If MyCounter = 0 Then
Sheets("to").Range("A" & i).Offset(1, 4) =
Sheets("to").Range("A" & i).Offset(1, 5) = Format(Date, "Mmmdd/yyyy")
MyCounter = MyCounter + 1
Else
End If
Next i
End Sub
Display More