Good Day
I'm having an issue with this line graph attached.
Basically I am keeping a running daily total year on year, I want the line graph to connect the lines for missing dates inbetween data but as you can see below, this new year has a giant line (orange) across the graph even though data isnt entered that far out as yet.
Any ideas on how to fix? I just have dummy info in 2021 currently but eventually in April this year there will be two lines that are close and I can see visually the difference from last year.
Thanks
Posts by stildawn
-
-
Not saying it would need VBA in Access but it might.
In excel it would in my opinion.
A shared workbook would be a nightmare I think, I have done them in the past and always horrible experience, plus the majority of users dont need to do anything other than bring up the costs they need. Data entry etc would be handled separately which is why I was thinking of a Access backend / frontend setup.
Does Access still have the free frontend version? As I'm fairly sure the company does not have Access for all users.
Access is going to be difficult for me haha, I haven't really done anything on it for years now and the user form to reference the data will need to be fairly complex in my mind, like the POL / POD names would need to appear as a user types them for example, as there will be literally hundreds and hundreds of port names.
-
Hi All
I am about to start a large ish (hopefully) vba project, and just after some more experienced advice/thoughts on it before I invest too much time.
My company (multinational) has a need for a database of freight costs, each freight cost will have 7 fields (maybe more):
POL (port name) / POD (port name) / Carrier (short string) / Start (Date) / Valid To (Date) / Type (a few set options) / Cost (number) ------- And maybe a few other costs types as well depending on what is needed.
These costs then need to be presented to each user based on what they enter for POL / POD / Carrier / Type etc.
Now I know I can do this in excel, have a sheet with all the rates as each row (hundreds of rows) and then a user form to present to the user, but I was thinking access might be better, having the rows as a backend database, and then a simple front end user form referencing that backend data.
I'm just after what you very talented and knowledgable individuals would do in this case before I invest too much time into it?
I am much much better at Excel vba than Access, but I have made smaller access programs in the past, although I'm worried about the backend being on a server shared drive and that causing issues.
Or is there a whole other alternative I could look into beyond Excel/Access, one that has a short learning curve as I would have to learn how to do this myself.
The backend/master freight costs data would need to be easily updated, excel/access is easy to do this via a template file etc but that needs to be considered.
Thanks in advance
-
Re: Simple Row Cut & Paste Not Working For Some Reason
All good simple fix
Thanks again
-
Re: Simple Row Cut & Paste Not Working For Some Reason
This part:
(wsN.Cells(wsN.Rows.Count, 1).End(xlUp).Row + 1, 1)
The original wasn't finding the new lastrow on the correct sheet.
Good to know about the cut command, I'll be sure to remember that in future. I usually copy and then delete as well but thought why not just have one line instead of two.
-
Re: Simple Row Cut & Paste Not Working For Some Reason
I fixed a referencing bit in your code to the below and it worked:
Code
Display MoreDim i As Long, ii As Long, wsI As Worksheet, wsN As Worksheet Set wsI = Sheets("Inbound"): Set wsN = Sheets("New") With wsI.Cells(1).CurrentRegion .Rows(1).Copy wsN.[a1] i = .Rows.Count For ii = i To 2 Step -1 If .Cells(ii, 20) = "N" Then .Rows(ii).Copy wsN.Cells(wsN.Cells(wsN.Rows.Count, 1).End(xlUp).Row + 1, 1) .Parent.Rows(ii).Delete End If Next End With
Don't know why yours worked and not mine though.
Thanks though
-
Hi Al
I'm sure I have used this code numerous times in the past but for some reason its not working.
I'm getting a 1004 error on this code:
Code
Display MoreSub SplitNew() '#### Copies Header #### ThisWorkbook.Sheets("Inbound").Rows("1:1").Copy ThisWorkbook.Sheets("New").Range("A1").PasteSpecial xlValues '#### Copies Only New Rows #### Lastrow = ThisWorkbook.Sheets("Inbound").Range("A" & ThisWorkbook.Sheets("Inbound").Rows.Count).End(xlUp).Row For i = Lastrow To 2 Step -1 If ThisWorkbook.Sheets("Inbound").Range("T" & i).Value = "N" Then LastrowN = ThisWorkbook.Sheets("New").Range("A" & ThisWorkbook.Sheets("New").Rows.Count).End(xlUp).Row ThisWorkbook.Sheets("Inbound").Rows(i & ":" & i).Cut ThisWorkbook.Sheets("New").Range("A" & LastrowN + 1).PasteSpecial xlValues 'ERROR HERE Else End If Next i End Sub
It doesn't matter how I rework it, I still get errors, for example if I do a simple "paste" then I get 438 errors:
Code
Display MoreSub SplitNew() '#### Copies Header #### ThisWorkbook.Sheets("Inbound").Rows("1:1").Copy ThisWorkbook.Sheets("New").Range("A1").PasteSpecial xlValues '#### Copies Only New Rows #### Lastrow = ThisWorkbook.Sheets("Inbound").Range("A" & ThisWorkbook.Sheets("Inbound").Rows.Count).End(xlUp).Row For i = Lastrow To 2 Step -1 If ThisWorkbook.Sheets("Inbound").Range("T" & i).Value = "N" Then LastrowN = ThisWorkbook.Sheets("New").Range("A" & ThisWorkbook.Sheets("New").Rows.Count).End(xlUp).Row ThisWorkbook.Sheets("Inbound").Rows(i & ":" & i).Cut ThisWorkbook.Sheets("New").Range("A" & LastrowN + 1).Paste 'ERROR HERE Else End If Next i End Sub
If I change the Rows to a range and the Range to a rows still get the errors.
Any ideas, this should work.
Thanks
-
Re: VBA code not working when using UNC path for saving file
Thanks S O
-
Re: VBA code not working when using UNC path for saving file
Yeah I know how to step through code haha, I have done that a few times, but I haven't noticed (by watching my computer and refreshing it) the mapping working from the code?
Anyway have a good sleep, no rush on this
-
Re: VBA code not working when using UNC path for saving file
Thanks S O looks intense.
Is there anyway to test this? I unmapped one of my network drives and then tried to remap and disconnect using the code while watching my computer haha, but nothing seemed to happen?
Is there also a way to check for already mapped letters so I can build that in?
-
Re: SaveAs Failed - I think because of network UNC
Here is the code instead of the picture (sorry that was the picture sent by the user):
Code
Display MorePrivate Sub MasMPOBut_Click() '##### Save as master file and close template file ######################### ThisWorkbook.Sheets("Settings").Range("A2").Value = 1 InstallPath = ThisWorkbook.Sheets("Settings").Range("A1").Value & "\" MPONo = ThisWorkbook.Sheets("Master").Range("D6").Value Vendor = ThisWorkbook.Sheets("Master").Range("D10").Value CurDate = Format(Date, "yyyy.mm.dd") On Error Resume Next MkDir InstallPath & "MPO Masters" On Error GoTo 0 MasterSavePath = InstallPath & "MPO Masters\" & CurDate & " " & MPONo & " " & Vendor On Error GoTo DupHandler MkDir MasterSavePath On Error GoTo 0 ThisWorkbook.SaveAs Filename:=MasterSavePath & "\" & CurDate & " " & MPONo & " " & Vendor & " Master File" & ".xlsm" MsgBox "New Master File has been saved at the following location:" & vbNewLine & vbNewLine & MasterSavePath & "\" & CurDate & " " & MPONo & " " & Vendor & " Master File" & ".xlsm" & vbNewLine & vbNewLine & "Please open new Master File to continue.", vbInformation, "New Master File" ThisWorkbook.FollowHyperlink MasterSavePath If Workbooks.Count > 1 Then Workbooks(1).Activate ThisWorkbook.Close SaveChanges:=False Else ThisWorkbook.Saved = True Application.Quit End If '############################################################################# Exit Sub DupHandler: MsgBox "Master file already generated for this MPO & date, please check folders and work from already created master file.", vbExclamation, "Master File Already Created" Exit Sub End Sub
Quote from S O;779068I'm pretty sure the MkDir command doesn't support UNC paths - but you won't see that in your code because of "On Error Resume Next"
If it can't create the folder, then your save path is invalid.
One option could be to actually map the drive within the code, and then disconnect it when you've finished.
Ahhhh that could make sense, so the real error could be that it can't make a directory on a UNC path.
Is there another make directory command that would work with UNC?
Or alternatively, can you advise how I would map the drive within the code, never done anything like that before. Would mapping/disconnecting cause any issues with their other windows experience? Like I assume they use the network drive for other work etc and I don't want code that would mess up their other experiences in using the network drive.
-
Hi All
I have a tool I've been developing, and basically when you run it for the first time, it asks you to point to a save location (which it then uses in future when making different files and saving different things).
My end user is getting an error on one of the save as commands. Here is the issue step by step:
Full path saved for useis: \\nzsrv01\companynz\CompanyShared\CLIENT RATES & INFORMATION\I\ICEBREAKER\CT BOOKINGS\2_SPO\SPO Masters\11.10_GHF
When the user runs the code this happens:
[ATTACH=CONFIG]70407[/ATTACH]Debugging to this line of code:
[ATTACH=CONFIG]70408[/ATTACH]You see its just a save as command. Now this works perfectly if the installpath (which is the full unc path listed above in this case) is a normal like "C:\Blah" path. But it seems to be throwing this error due to the unc network path, even though as far as I know Excel vba should accept these paths.
Any ideas/tests I can do to figure this out.
I know I could map the network drive, but eventually multiple users will be using this so would rather avoid having the users do any mapping etc.
Thanks
-
Re: Comparing two sets of data (ranges, rows, columns whatever) and find changes
There is other data that doesn't change (automatically) in other columns that needs to be manually updated based on the changing data that my code handles.
So no replacing old with new is not what I need.
Code/process I need is like this random example:
OLD DATA
[tr]
[TABLE="width: 500"]
[td]QTY
[/td]
[td]Delivery Date
[/td]
[/tr]
[tr]
[td]5
[/td]
[td]22/09/16
[/td]
[/tr]
[tr]
[td]10
[/td]
[td]21/09/16
[/td]
[/tr]
[/TABLE]NEW DATA
[tr]
[TABLE="width: 500"]
[td]QTY
[/td]
[td]Delivery Date
[/td]
[/tr]
[tr]
[td]4
[/td]
[td]22/09/16
[/td]
[/tr]
[tr]
[td]10
[/td]
[td]24/09/16
[/td]
[/tr]
[/TABLE]In these lame examples (there is both more columns to compare and many many more rows), I need code that will compare the data in "NEW DATA" to the data in "OLD DATA"... In these examples it would highlight both rows in "NEW DATA" cause both rows have changed, the QTY on row 2, and the date on row 3.
If the data was identical, it wouldn't highlight.
Does that make sense.
-
Re: Conditional Formatting - Changing to #REF!
Basically here is the sequence of events.
Master sheet has a bunch of data on it, including conditional formatting (as above).
> This master sheet is saved as a xlsx (to remove code) the person A sents it to person B, Person B enter in data into column L. Column L then highlights etc due to the conditional formatting rules.
>> Person B save this (with the added data) and send back to person A
>>> Person A runs the code to import the data that Person B provided (in the xlsx file) into the master file (xlsm with the coding). The code dumps all the data from the xlsx, into the "Import" sheet of the xlsm file. It then runs the code above to copy across the relevant data from "import" to "master" sheet, both the import sheet and master sheet have the same conditional formatting rules on them, however when the code copies across the data from "Import" to "Master", the conditional formatting rules on the "master" sheet now shows the #REF! errors...I think your right though in that when I delete row 9 in the "Import" sheet, it destroys the conditional formatting on the "Import" sheet, and then when it copies across to "Master", it also copies the now destroyed conditional formatting from "Import" to "Master"
I'll redo the code so that it doesn't delete rows 1 - 17 on the "Import" sheet and see if that changes it.
-
Hi All
I have a sheet (old version), it has say 4 columns of data on multiple rows (can be thousands).
On another sheet, I have the same data (new version), however some rows might have changes...
I need vba code to compare the new data with the old data. If there is a change on a row ideally I want to highlight that row a color (grey for example but I can mess with this later).
The idea behind it is that a person will have to update the rows, and I want to highlight out the rows that have changed so they don't have to actually update every row every time, but just the ones that have changed.
I know I can do this with an insane loop, but again I'd like to avoid loops if possible due to the data size and processing time it would take.
-
Re: Conditional Formatting - Changing to #REF!
It deletes rows 1 to 17 on the import sheet, but row 9 still very much exists on the master sheet which is where the conditional formatting is.
Unless your saying that when it copies across the data from "import" sheet to "master" sheet it copies the conditional formatting also?
-
Hi All
I have a master sheet, which has some conditional formatting in L18 down. The formula is this: =L18>$D$9+7
This is set and working fine.
In the process, we load in some data from another workbook, and put it into the master sheet with this code:
Code'##### Clears out the unwanted data on import sheet & copies across #### With ThisWorkbook.Sheets("Import") .Rows("1:17").Delete Lastrow = .Range("A" & .Rows.Count).End(xlUp).Row .Range("L1:N" & Lastrow).Copy ThisWorkbook.Sheets("Master").Range("L18") End With '#######################################################################
As soon as this part of the code runs however, it somehow messes up the conditional formatting on L18 down in a weird way...
Turning it from the correct formula: =L18>$D$9+7
To: =L18>#REF!+7I don't understand why/how its losing the "$D$9"?
There is another conditional formatting formula that is slightly different but it does the same thing, it loses the "$D$9" replacing it with the not working "#REF!"
Any idea what is going on, and how do I fix it?
-
Re: Pipe "|" Delimiter CSV?
Quote from cytop;777504Opening a file 'For Output' will create the file if it doesn't exist, or truncate any existing file.
Yes. You can do that if you wish, but there is no particular advantage doing it that way.
Just covering all bases. You suddenly mention something that is non-standard for a CSV file so tried to cover that. If the character is already in the cells then it will be included.
I just coded it to do it within excel, but the loop is fairly slow, takes a minute or two on big files, will try your print to file way as well and see which is quicker.
-
Re: Pipe "|" Delimiter CSV?
QuoteNo problem, you just name the file with any extension you want (Even .XLSM). when writing to a file, the extension you use doesn't really matter as long as the program reading the file can understand the structure.
So would I not need to create this "csv" file first? Would simply having it as the "open "blah.csv" For output as #1" work?
The "~" is already in the last column of the work sheet, so I believe your code will automatically include it correctly.
Could you explain why doing it within excel (into A1) would be a pain? Wouldn't it just be something like:
CodeFor j = 1 to UsedColumns - 1 .Range("A1").Value = .Range("A1").Value & .Cells(i,j).Text & "|" Next j
Wouldn't that work? Or is there something I'm missing.
-
Re: Pipe "|" Delimiter CSV?
Quote from cytop;777439You can't 'natively' save a file using delimiters other than a comma, tab or space.
You can change your computer settings to use '|' as the text delimiter.
Access can be used to export a table (as a linked table) using the '|' as the delimiter, although you may not have a copy of Access to hand. You can use ADO/DAO to open an Excel file as a database and export that but that means more code and more complication and the worksheet must be a simple list like a database.
As infomage said (posts overlapped), you can save as a 'standard' CSV and edit the file. This can also be automated - again more code and more complication.
The only other alternative is to use VBA to write to a file using '|' as the field delimiter
Code
Display MoreSub ExportPipe() Dim UsedRows As Long Dim UsedColumns As Long Dim i As Long, j As Long '// Define a suitable file name Open "C:\temp\pipedexport.txt" For Output As #1 With ActiveSheet UsedRows = .UsedRange.Rows.Count UsedColumns = .UsedRange.Columns.Count For i = 1 To UsedRows For j = 1 To UsedColumns - 1 Print #1, .Cells(i, j); "|"; Next j Print #1, .Cells(i, UsedColumns) Next i End With Close #1 MsgBox "Finished...", vbInformation End Sub
(Quick & Dirty)
Thanks Cytop, this looks the best solution.
Can you run me through the code so I can best implement it into my code:
They need it in a ".csv" file, can I edit this file name code to generate dynamically something like:
CodeOpen ScoutSavePathStr & "\Scout Upload " & RefNoStr & " - " & CurrentDateStr & ".csv" For Output As #1
Or do I need to actually generate this file before the above? Basically currently I have all the data in a sheet called "Scout" (which is the system its uploading to), need to get all the data in that sheet into a piped CSV file.
CodeFor i = 1 To UsedRows For j = 1 To UsedColumns - 1 Print #1, .Cells(i, j); "|"; Next j Print #1, .Cells(i, UsedColumns) Next i End With
From what I understand, this loop is simply going through all used cells in the sheet and printing the contents + "|" into the text file (the output file). Will this work as is with a csv file?
EDIT: Just re-reading the instructions from the Scout people (who are making this a pain in the ass lol), here's there vague instructions:
Quote1. Fill in the data in one cell, use | as delimiter and remember to enter ~ as Line End Indicator of each line.
2. Save the file as Comma delimited CSV
3. Send email to "[email protected]"domain.com with the CSV as attachment, Subject: ReferenceCouldn't the above code work straight in excel without the print to output? Just do the above in A1?
Thanks