I've developed an application that uses excel/ VBA to interface a MySQL database in a WAMP configuration. One of the features of this application is the automatic saving of cells values, including the colors of words, font style, font size etc. The application loads up a calendar and renders the entered cell text upon workbook open.
This is achieved through breaking down the cell value into characters and storing them into a cell_value table that references other objects within my database in the following manor
+----+-------------+------------+------------+----------------------+--------------------+
| id | employee_id | project_id | date | cell_value | font_color |
+----+-------------+------------+------------+----------------------+--------------------+
| 1 | 1 | 1 | 2015-01-07 | the weather is crazy | 1:14:70,15:20:2000 |
+----+-------------+------------+------------+----------------------+--------------------+
this table stores the text entered by person with id=1 for project with id=1 on '2015-01-07'. The cell value is 'the weather is crazy'. the font color is listed in a comma delimited string with each element of this string delimited by a colon.
+--------------------------+------------------------+------------+
| starting_character_index | ending_character_index | font_color |
+--------------------------+------------------------+------------+
| 1 | 14 | 70 |
| 15 | 20 | 2000 |
+--------------------------+------------------------+------------+
I have been using the cell_selection_change event to trigger an automatic write to the database to store the contents of a global called LAST_SELECTED_CELL (as the active cell is set prior to the user making changes to it and hence does not cater for writing to the database AFTER the user makes changes to the contents of the cell).
this method works although is prone to bugs and for large amounts of cells and complex cell font/ color configurations is slow.
I was looking into using a spreadsheet embedded into a userform as potentially a better way of doing a similar process however i've found it to be quite buggy and prone to crashing. Is there a tool out there that allows you to embed a single excel 'cell' into the userform instead of an entire workbook?
If not, is there anything else that could be modified to suit my needs? Or do you have any suggestions as to how to improve my current method of storing/ rendering the data
Kind regards
Jordan
You can't. There is no way to embed Worksheet into the userform. But...
You can imitate it via using ListBox. It provides a way to display data as Excel Sheet displays rows and columns. It gives you a possibility to select single row or multiple rows at a time. You can make visible only one column, the rest of columns can be hidden (use ColumnWidth property).
Cheers
Maciej
Related
I am currently doing a sales summary consist of lots of customers, and I am trying to find a way to automatically update the value from the main sheet to individual customers sheet as there are too many customers for me to do that.
The Main Sheet would look like like this with headers
| Serial| | Date | | Customer Name| | Product Info|
| 001 | |Jan4th| | Mike | | Apple |
i am trying to create a formula so that the other individual sheet could only extract rows that was from only the customer (Mike), and other sheets would be of other customers as well.
It would help a lot if the formula can auto add in value that would soon be update as well, as other method i found only able to distribute available values, and when there are new value to be add, i have to repeat the process again which is not effiecent given the number of customers i have to summary for
If not formula then any other method would help too, but VBA is a bit above my capability so if you can provide detail for how i can make use of it, it would be delightful
If anyone can come up with anything i would be grateful, thank you for your attention
i have tried the copy paste link but they do not auto update new value after the paste.
First question on Stack, but not my first visit!
Basically I have this huge Excel database (>24 000 rows, merged from different tables) I have been working on for weeks and now that I'm done adding new entries, I have to clean it by removing a lot of duplicates.
The array/table is structured in the following manner :
+---------+-------+--------------------+-------------+--------------------+
| Company | Name | Address | Phone | Email |
+---------+-------+--------------------+-------------+-----------+--------+
| Baij&Co | Steve | 458 Preston avenue | 4156854789 | steve#baij&co.com |
I did search through conventional methods but they don't exactly answer my problem, such as:
Using the "Remove Duplicates" Excel button by selecting all columns to make sure I only keep unique values
Using the filtering method to identify the duplicates and then remove them.
However, my goal is to remove the duplicates for which the given row(s) contains the minimal amount of information, as shown in this example:
+--------- +-------+--------------------+-------------+--------------------+
| Company | Name | Address | Phone | Email |
+--------- +-------+--------------------+-------------+--------------------+
| Baij&Co | Steve | (blank) | 4156854789 | steve#baij&co.com |
| Baij&Co | Steve | (blank) | (blank) | steve#baij&co.com |
| Baij&Co | Steve | 458 Preston avenue | 4156854789 | steve#baij&co.com |
Here, I would like to remove the 1st AND 2nd row as they contain less information (missing address & phone entry) about the same contact.
Does it makes sense..?
I only know the basics of VBA (like creating a userform to add a new contact and fill out the entered information in the right cells) but I struggle with advanced algorithms.
I just know the VBA related function cannot be customized, apart from selecting the columns in which I want to remove the duplicates :
Sheets("Database").Range("ContactsTable").RemoveDuplicates Columns:=1:15, Header:=xlNo
Any ideas?
Thanks fellas!
So I followed #Tim Williams 's suggestion (which is similar to Scott's actually) and did the following:
I realized that email addresses were the unique identifier (or primary key) and I have to delete rows that don't contain any (as it becomes useless to have a contact file without contact information).
I added a column named "Count" and inserted the following formula:
=COUNTIF(N:N; N2)
--> Here, "N:N" is the column containing all email addresses. "N2" being the first cell.
I then sorted the table by descending order on the newly "Count" column to have the most occurrences first.
Then used the "Remove Duplicate" Excel tool and selected the email address column.
As a result, 10 000 rows have been removed (out of 24 000). One thing for sure is this table contains now unique contact files based on the email address. However, I will never know for sure if the most filled row was kept for each contact sadly (unless I spend days comparing both databases, row after row).
Problem solved I guess! Although I would be interested in a VBA-script to do the same (to learn on the algorithm aspect) if anyone knows anything about it :-)
Thanks again!
First let me explain what I want to achieve.
I currently have an Excel like this:
Names | Standards
James | Standard 1
James | Standard 2
James | Standard 3
Francis | Standard 1
Francis | Standard 2
Francis | Standard 3
Leon | Standard 2
Leon | Standard 3
Peter | Standard 2
Michael | Standard 3
And I want to create something like this:
Standard | Name 1 | Name 2 | Name 3 | Name 4
Standard 1 | James | Francis | |
Standard 2 | James | Francis | Leon | Peter
Standard 3 | James | Francis | Leon | Michael
My real Excel has more than 300 standards, so I would like to automate this using Excel Formula. I know this is possible, but I haven't used Excel in a while, so I could use a push in the right direction.
Couple of things I need (I think):
Need to count how many times people in the names column mention a standard. So I want to know that I need 2 names for standard 1 and 4 for standard 3. I think I can do this by using the COUNTIF method.
We need to search for the location of the standards. I think I can do this by using the Match function. This gives us the location of the first match in my original Excel. By sorting my original Excel a-z and combining it with the countif result I know where all the matches are (first match + countif = location of the last match, and everything inbetween is also that standard).
For the first name that mentioned a standard, I will reference the cell left of the first match (because the names are in the cell to the left of the standard I found). For the second name I will reference the cell left of the cell below the first match. I keep doing this till I find as many names as Countif mentioned. So I need an IF statement that makes sure that if 2 people mention standard 1 only gets 2 names and 2 cells with a "".
How will I reference the cells? By another if statement that uses this: Excel Reference To Current Cell , Correct me if I am wrong, but can't I then just say THIS.CELL=cell location I found (probably should use INDIRECT here?).
This is just me brainstorming, but I would love to know if people have any other ideas for my problem or have some feedback for my current plan.
An important thing to mention is that I want to do this using Excel Formula. I do realise that this isn't always the best, but VBA is not an option atm. I am also not worried about performance issues, because I think i'll just copy all the values after I found all the names using formulas.
Thanks in advance!
Depending on how you want to have the layout, I think you should use a pivot table. Drag the 'Standards' and 'Names' fields to the 'rows' data box and then right-click on a standard, click 'Field Settings' - 'Layout and Print' - 'Show item labels in tabular form'. (See example below.)
If you definitely need the data in the format in your question, I would edit the pivot table by dragging the 'names' field to the 'columns' data box. Then drag the 'standards' field from the field list above a second time and duplicate it in the 'values' box (see example below).
In the space underneath the pivot table, use an IF formula to only copy the name if there is a 1. This kind of approach will obviously be quite fragile, so if you can make do with the first approach, I think you will run into fewer problems in the future.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I had the following situation:
Spreadsheet used to calculate pricing for a bunch of different kinds of trees. (I'm a tree farmer)
This data has two uses:
I use it in Markdown to make tables on my web page.
I use it in kijiji ads.
The latter made things sticky. Cut and paste from excel leaves data separated by single tabs. Nothing lines up. A pasted table in excel in some program like Kijiji looks like this:
| Bareroot Bundles of 25 2-3 year olds ||||
| Bundles | # Trees | Cost | Price Per Tree |
|: ------------- :|: ------- :|: ------- :|: ------------------- :|
| 5 Trees | 5 | $30.00 | $6.00 |
| Single Bundle | 25 | $75.00 | $3.00 |
| 5 Bundles | 125 | $300.00 | $2.40 |
| 10 Bundles | 250 | $525.00 | $2.10 |
Yuck.
If I have a table like this:
I would do it with the following steps:
Add the header separators from a new row using a bunch of -, making sure that there is more than than less:
Insert additional columns to contain the column separators, then select the cells that will have the separators. Insert the separator and then, instead of pressing Enter, I would press Ctrl+Enter to fill all the selected cells at the same time:
Format everything to the font Courier New, adjust the alignments and column widths:
Save as Formatted Text:
This will look like this if you open the file in notepad:
Here's a couple recipes for using excel data.
Layout your spreadsheet as normal.
Insert a blank row for the formating row.
Create a wide column to the right of your table
Each row corresponding to a table row has a formula something like this:
"|"&A1&"|"&B1&"|"&C1...
The pipe symbols are for markdown, but also serve as cell boundary markers.
You will need to modify for possible grouping. E.g. A one line title on a 5 column table will end up being
"|"&A1&"||||"
In the blank cell corresponding to the formatting row, type an appropriate string of |:--------:|...
My problem was a bit messier than that. I advertise on Canada kijiji (not the same as the US version) They allow some formatting in ads but do not have a table format at all.
I needed as ascii text table. The results of cut and paste from excell into a text processor are less than stellar, as data is separated with a single tab character. Anything that lines up is coincidence.
My route was to take this notion one step further, and make an ascii formated column that would work for either MMD or for text base ads.
First attempt:
"|" & A1 & REPT(" ",15-LEN(A1)) &
"|" & B1 &...
I didn't like the hard coding of the column widths.
And if your source column is $2.50 it comes across as 2.5
Second attempt.
1 blank column for each column I want to use.
If our table is 5 columns wide, I need another 5 columns. Let's suppose the data I want is columns A-E. I will create F-J for formatting.
F1 in this one has the formula
=TEXT(A1,"$0.00")
Replicate across and down as needed. If the source text is already a string, it doesn't matter, it will come across unchanged.
Secondly, insert a row above. In this row, but the column width you want for the output.
Now your formula for K2 will look like this:
"|" & F1 & REPT(" ",K$1-LEN(F1)) &
"|" & G1 ...
At this point if I want flush right text, I have to reverse
the REPT and the Cell reference. No thoughts of centering.
The end result is this
|Bareroot Bundles of 25 2-3 year olds ||||
|Bundles |# Trees | Cost| Price Per Tree|
|:-------------------|:---------|---------:|--------------:|
|5 Trees |5 | $30.00| $6.00|
|Single Bundle |25 | $75.00| $3.00|
|5 Bundles |125 | $300.00| $2.40|
|10 Bundles |250 | $525.00| $2.10|
In use, then I can cut and paste from my spread sheet, and just clip off the extra pipe symbols on the right edge of the top row.
I'll try to make sense of this the best I can. I'm pretty horrible at making things clear. :) So...here it goes....
I have a spread sheet that is a list of seeds I have for growing peppers. Here are the columns I have, and I will explain more after.
Crop | Color | Generation | Species | Source | Scoville | Flavor | Heat | Notes | 2012 Type | 2012 Name 1 | 2012 Name 2 | 2013 Type | 2013 Name 1 | 2013 Name 2 | etc.
Ok. So "2012 Type" is a list that will contain either a blank, "N", "O", or "M". All I care about is whether it is blank or not for this question. If it is NOT blank I want to highlight the Crop name with a green background to show that I have grown this crop. To do that through the Conditional Formatting is a no brainer. However, my issue begins when I, as usual make things more complicated. When I add "2013 Type", "2014 Type", etc. I want to check for those also. So then my formula becomes an OR; is there a value in 2012 or 2013 or 2014, etc. Part of question is that. How do I write a formula that is dynamic enough to pickup the new fields I add each year...2015 Type, 2016 Type...etc.?
I also have a ton of other stuff going on, but I think I may have that figured out...sort of.
Thank you for your help, appreciate it.
Edit: Okay. I feel I need to explain how I am trying to develop my whole worksheet, one to check my thinking, and two to clear up the goals.
In addition to what I have explained above, I have tabs that read 2012, 2013, grown, not-grown, MasterList, and Criteria.
MasterList is what we are talking about here.
Criteria is what I am using for an advanced filter to copy crops that to the appropriate sheets. So, if I have a a crop marked in column "2012 Type", then it will be copied to the 2012 sheet. It will also be listed under the tab Grown. Same if it were marked under "2013 Type" etc.
Basically, I am using tabs to filter out specifics from my MasterList so that I can find what I'm looking for quickly, or view everything as a whole.
Once again, I am great at making things over complicated. Couple that with the fact that I am still fairly new to Excel coding...and you have a disaster. :)
Thank you all for listening. :)
Try using a COUNTIFS formula in conditional formatting, e.g. this formula
=COUNTIFS($1:$1,"*Type*",2:2,"<>")
....will count the number of cells in row 2 which have some value....and where row 1 has "type" contained in the header row for the same column.
For your condition you want to know whether the result of the COUNTIFS formula is zero or not (zero signifying no entries in any of the type columns for that row) so for green use
=COUNTIFS($1:$1,"*Type*",2:2,"<>")>0
Note: COUNTIFS is only available in Excel 2007 and later, for earlier versions you can use this formula
=SUM(ISNUMBER(SEARCH("type",$1:$1))*(2:2<>""))>0
Actually for an annual exercise I would just go for amending the conditional formatting as part of your procedure when you add the columns with the OR in it as you mention it.
The condition should be (as you probably already know):
=OR(ISBLANK($J2),ISBLANK($M2))
I'll have another thought about making it smarter but I have a feeling already that will involve some more coding and such, making the effort for this bigger then the benefit for the annual updates.
You might consider reformatting your data so that it only grows in the row direction and not the column direction. I'm thinking
Crop | Color | Generation | Species | Source | Scoville | Flavor | Heat | Notes | Year | Type | Name 1 | Name 2
Then you could use pivot tables, formulas, and array formulas to present the data in various ways.
I would create a worker column(you can always hide it later) that concatenates all your Type columns together into one column:
=CONCATENATE(K2,N2,Q2,T2,W2,Z2,AC2,AF2,AI2,AL2,AO2,AR2,AU2,AX2)
=$A$2:$ZZ$10000
=IF($A2="",FALSE,TRUE)
It's important that you enter the formulas and conditional format formulas and applied to range accurately - with the correct syntax(notice the use of $).
Good Luck.