Excel SpecialCells(xlCellTypeBlanks) fails with merged cells - vba

Excel SpecialCells(xlCellTypeBlank) includes all cells in a merged range, regardless of whether they are blank. I consider this to be a bug, and I desperately need a workaround. Steps to duplicate:
(1) Create a worksheet with some text in cells A1 and B3. Now activesheet.usedrange.cells.count = 6 and
activesheet.usedrange.specialcells(xlcelltypeblanks).cells.count = 4
These values are as expected.
(2) Now merge cells A1:A2, and
activesheet.usedrange.cells.count = 6 and
activesheet.usedrange.specialcells(xlcelltypeblanks).cells.count = 5
Both A1 and A2 are now considered blank.
I need to find a way to select just cells A3, B1, and B2 in this case. I'm actually doing this using .NET Excel Interop, so I do not want to have to actually retrieve the cell value as a part of the test, since this is a huge performance penalty in Excel Interop; so I'm restricted to an internal cell selection function such as SpecialCells.

I got this to work by selecting smaller ranges at various places in the code, usually just before doing any cell merging. I consider this to be a workaround, not really a solution. Thanks to those who commented - you helped inspire this workaround.

Related

LibreOffice Calc: how to highlight the maximum value of ranges of cells at once?

I would like to highlight the maximum value for each group of cells using conditional formatting, and applying it at once.
In order to explain myself better, the file is something like this:
(But the real content has more than 1500 of these).
For each range in each column, I want to highlight the maximum value. So, for the range A1:A11, the cells A2, A5, A7 and A10 should be with a different format. The same for the range A18:A28, where A26 and A28 should be different, and so on for B, and C, etc.
I have tried selecting A1:I28 and apply conditional format where cell is equals to max(a1:a11) apply a good format, but it doesn't work well. It think I don't how to use the references in the sheet in order to be considered in a right way.
Any ideas?
AFAIK you can't do this "at once", thus in a single step. To get this working with a spreadsheet layout as in your example, you'll have to define the conditional formatting for each "dataset" separately (it would be easier if the spreadsheet wouldn't contain two "rows" (1st: 1-11; 2nd: 18-28) on the same sheet). With dataset, i mean the distinctive ranges A1:A11, B1:B11, ... A18:A28, B18:B28 and so on.
To be more precise: you need to define the conditional formatting rule for the first dataset of its row (in your example: A1:A11 and A18:A28, respectively), then you can apply it to the other datasets using format pasting.
To do so:
define the conditional formatting for range A1:A11 with formula A1=MAX(A$1:A$11). Notice the dollar signs - without them LO will compare A2 to MAX(A2:A12), A3 to MAX(A3:A13) and so on. The dollar signs make sure that every cell in A1:A11 will be compared to exactly that range only.
Select A1:A11, copy it;
Select B1:B11 and paste just the formatting, using the "Paste Special" functionality (Menu Edit -> Paste Special... or SHIFT+CTRL+V, select Format only in the Paste Special dialogue).
Repeat step 3 for C1:C11, D1:D11 and so on till I1:I11;
Repeat step 1 and 2 for A:18:A28 (formula should be A18=MAX(A$18:A$28));
Repeat step 3 for B18:B28 and so on.
If you try to paste the formatting to more than one column, LO won't handle the target range as entity but will define the formatting for each cell, thus it will define a conditional format for B1 with formula B1=MAX(B$1:B$11), B2 with B2=MAX(B$2:B$12) and so on. It's vital to have only one conditional format definition for each separate range, thus for A1:A11, B1:B11 and so on. You can control how LO had handled your modifications by checking the resulting conditional format definitions in Menu Format -> Conditional Formatting -> Manage....

Writing a cell in Excel

This query might seem a bit childish, but this has been bugging me for quite a few days.
I am completely new to Microsoft Excel and want to know how do hold same values in two different excel cells?
Example: Cell A1=bandwidth Cell E1=[minimum:bandwidth():utilization]
I want the word "bandwidth" to be same in both the cells. So if the user
inputs "bandwidth" into cell A1, then this generated into E1.
Kindly help me with this one.
In E1 enter the formula:
="minimum:" & A1 & "():utilization"
as you update A1, the displayed text in E1 will follow.
Adding to the solutions already given, you can define the format to be used for A1 with the TEXT function:
="minimum:" & TEXT(A1,"#,##0.00") & "():utilization"

Excel Cell reference that will go to the left

I am using an excel spreadsheet formula to add two cells together and I want to have it reference one row from left to right like it normally does, but I need it to reference the same row in another page in reverse, and then be able to drag the formula through the entire worksheet. I cannot seem to find anything like this when I look online. TLDR I need to know how to tell excel reference the cell to the left if I drag it to the right.
so I need to add A0 in page one and A9 in page two then when I copy the formula to the left I need it to grab A1 and A8, is there a way to get this?
Your question is not very clear; for example, you talk about a formula but have an Excel-VBA tag. However, I think I understand the effect you seek.
I have filled A1:I1 of the current sheet and A1:I1 of worksheet “Sheet3” with numbers.
I have typed the following formula into another cell within the current worksheet:
=A1+INDEX(Sheet3!$A$1:$I$1,,10-COLUMN(A1))
The target area for the INDEX function is Sheet3!$A$1:$I$1. This is a one row range so I do not need a row number. The column number is 10-COLUMN(A1) which is 9 so this formula is equivalent to:
=A1+Sheet3!I9
If I copy the formula one cell to the right I get:
=B1+INDEX(Sheet3!$A$1:$I$1,,10-COLUMN(B1))
This is the equivalent of:
=B1+Sheet3!H9
You can continue copying the formula to the right until you get:
=I1+INDEX(Sheet3!$A$1:$I$1,,10-COLUMN(I1))
Attempting to copy further gives an error because 10-COLUMN(J1) is zero and there is no column 0.
There are other methods of achieving this effect. The key feature of any such method is the expression N-X where N is a constant and X gets bigger as the formula is copied further to the right.

Converting Bulk Text to Hyperlinks in Excel

I am using Excel 2010. I have a column (A), for example that has about 500 numbers, all different. The number in each cell is slightly different. I want to turn them into hyperlinks in bulk(that's easy) if you have the same URL. The twist is that they all have different URLs BUT the URL are not that much different. They are the "same" URLs but the number in the cell is inserted at the end of the URL and that's a specific page.
EXAMPLE.
The first 3 rows (A1, A2, A3) are the numbers (977, 981, 961)
The URLs would show as PleaseHelp.com/index=977 , PleaseHelp.com/index=981, PleaseHelp.com/index=961
I want to put the hyperlink PleaseHelp.com/index="(A1, A2, A3)" and automatically insert what ever is in Row 1 and automatically insert the number and make it a hyperlink.
I know that I will have to use VBA to code but its tough.
A really easy way would be
B1 = HYPERLINK(CONCATENATE("http://www.something.com/index=",A1))
or
B1 = HYPERLINK("http://something.com/index="&A1)
(thanks Siphor)
then you could just fill that down.

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"