Merge cells if value exceeds the width of the cell - vb.net

I need to merge two cells if the contents or value of the cell exceeds the width of the cell.
For example, I have text that is 1000 characters, when writing it automatically wraps to the next line. I need to merge the cells so that the contents will fit into one cell.

Related

DataGridView: DataGridViewAutoSizeColumnMode.AllCells doesn't honor header cells

All my columns, except the last one, are set to DataGridViewAutoSizeColumnMode.AllCells. The last is set to .Fill.
However, when the grid is displayed, 2 of the non-last columns have header cells that wrap - their contents are wider than the contents of the non-header cells below.
Any ideas why the widths of the header cells aren't being taken into account by the column autosizing?

excel rowheight - a bug here?

Excel seems to work with the row heights in the following (il)logic:
If you refer to a single cell and your cell is defined "Wrap Text" and the row height is "Autofit":
When you enter more characters than what can fit to the cell width the row in the cell is changed automatically and in the end, when you press "Enter", the row height is expanded so that the whole text is visible.
If you refer to combined cells and your cell combination is "Wrap text" and "Autofit":
When you enter more characters than what can fit to the combined cells' width the row is NOT changed automatically and after "Enter" the row height is NOT adjusted to show the whole text.
I think this is not logical.
What would be the trick to get excel to automatically adjust the row height also in the case of "Wrap Text" combined cells? Any VBA solutions? (Basically you could, maybe, count how many line changes the combined cell has and adjust the rows.height property accordingly but...

Count number of times data is repeated in a column and show number in another column?

I have a UserForm that finds and copies a range of data and pastes it along with new data from the UserForm into a different sheet. I am wanting for it to also count the number of times some of that data is repeated in the new sheet. I have tried several different approches but none are working. Right now this is what I have:
.Range("I1").Value = iVal = Application.WorksheetFunction.CountIf(Range("A3:A103"), "CrisisNameTextBox1.Value")
This puts "TRUE" in the corresponding cell instead of the number of times the data is repeated.
You probably could use this function in the corresponding cell:
=COUNTIF( [range], [cell] )
The [range] is the range you want to check (use $ to make sure its value does not change from one cell to another)
The [cell] is the cell you are currently checking.
Assign the function to the cells you want and it should work
If you want to drag/copy this formula from one cell to an other : use the $ character to lock the coordinates you don't want to be changed. I.e :
$A1 Will prevent the column from being changed, but will allow the row
A$1 Will prevent the row from being changed, but will allow the column
$A$1 Will prevent both coordinates from being changed
The same applies to ranges ($A1:$F15, $A1:F1, $A$1:F15, A1:$F15, etc.)

Number to be copied from cell with the same number format and show it as a label for a shape without any change in the number format

I have a cell in excel which contains a value, lets say 100000.
Now i want this value to have commas in between them to represent the thousands and millions i.e. 100,000. I can do this by changing the number format in the home menu.
Now i want this value to be copied from that cell and paste it as a label for a shape. When i am doing this the commas go away showing me just the numbers.
I want it to happen through VBA but this is not happening in excel itself.
Does anyone have a plausible solution for this?
In range object use Text property, like this:
Sheet1.Shapes(1).TextFrame.Characters.Text = Range("A1").Text

Working with merge and center cells in Excel using VBA

If I take a range over merge and centered cells in excel, are each of them addressed as single cells or the group of cells constituting them? For example, if the cells A1 to A10 are merged and I do a
Worksheets(1).Range("A5")
Would this return the range of a single cell among those constituting the merged cell or a range consisting the merged cell itself? And what value would it contain if I get its value?
In other words, how would you represent range over merged cells in excel VBA?
Also, how can I get the range of the non merged cells adjacent to the length of this merged cell?
In other words, how would you represent range over merged cells in excel VBA?
By addressing it with the top left cell. Ex: "A1" in this case.
When in doubt, check it yourself first. If still in doubt, search google or whatever search engine you use. Still if something is unclear, ask :)
Would this return the range of a single cell among those constituting the merged cell or a range consisting the merged cell itself? And what value would it contain if I get its value?
It would return a single cell A5 which doesn't have anything in it because when you merge cells the data from the top left cell is kept and rest discarded. The reason why I say discarded is that if you now unmerge the cells, you will not get your values back.
Best way to check:
Let's say A1 to A10 had 1,2,3..10. Merge them. The cell will now have only 1
Try this in Immediate window
?Range("A5").Value
You will get nothing. Similarly if you want to write to it, you cannot use Range("A5").Value = "Blah". You have to address it with the top left cell. For example
Range("A1").Value = "Blah"