tadvstringgrid not copying every cell - properties

I have this tadvStringGrid
it has:
navigation.allowclipboardAlways=true
navigation.allowclipboardshortcut=true
option.goRangeSelect = true
MouseActions.DisjunctRowSelect = true
goEditing=true
I can select multiple cells but when i ctrl-c and ctrl-v ( at another location) only the last cell selected is copied.
Is there a property which needs to be turned on to have all the cells copied.
Or do i have to create a list of the selected cells and copy them at the new location?
ex:
Table:
1 2 3 4 5 6
7 8 9 10 11 12
if i i select 1,2,7 (ctrl-c them)
then click on cell 4 and ctrl-v
the 4 will change to 7 but the rest will remain unchanged.
i would like for 4 to become 1, 5 to become 2 and 10 to become 7.
thank you

After much searching.
To solve my issue, i had to turn off editing
which gave me acces to all the selected cells.
I saved the X Y coordinate with its value in a temp variable on the copy event
Made a list of those variable and on the paste event i would copy the list to the desired location.
This is more complicated way than needed but i cant find the easy way. so if anyone has a clue, I'll take it
thank you

Related

Copy the last entry row of a dynamic range and paste into to another workbook without displaying it

I would like to copy and paste the last entry row of a dynamic range into another workbook without displaying it and without opening it, if it is possible.
For instance in the following case I would like to copy and paste row number 3 which the last entry in a dynamic range into the new workbook:
A B C
1 18/08/2017 11 Medium risk
2 18/08/2017 11 Medium risk
3 19/08/2017 12 High risk
4 18/08/2017 11 Medium risk
I hope to have been more clear with my question and I hope it may help. Many thanks for your help.

Using VBA to create a grid from 3 spreadsheets with the row, column, and values

I have three excel spreadsheets. The first has the values that are to be assigned to a new excel spreadsheet. The second has the column that the data belongs in. The third has the row that the data belongs in.
It looks something like this:
Data Value:
1 5 7 9
2 2 6 8
Column Number:
1 2 3 1
2 3 1 2
Row Number:
1 2 3 2
4 4 3 1
How can I combine all of this information to create a single spreadsheet that contains the values in a format like this:
Column
1 2 3
Row
1 1 8 0
2 9 5 0
3 6 0 7
4 0 2 2
I have tried to do it by using loops in vba, but I am a beginner and I am having some difficulty.
I know that I need to use a loop that checks the row and column that the data is supposed to be in against the row and column for each iteration. I am just not sure how to go about doing that.
Assuming these are different sheets in the same workbook (if not - create a new workbook and copy the sheets over). I assume that on each sheet, the same range of cells is used (for example A1:D2 in all 3 cases with the values on the first sheet, the column numbers in the second and the row numbers in the third). You can dispense with VBA entirely at the expense of using some complicate formulas (inspired by this excellent article: http://exceluser.com/blog/1043/how-to-create-two-dimensional-lookups-in-excel-formulas.html )
Step 1. Add a fourth sheet and in A1 add the formula
=CONCATENATE(Sheet3!A1,"_",Sheet2!A1)
and copy it over the appropriate range (e.g. A1:D2). This will give you things like 2_1 which tell you that the corresponding entry in sheet 1 belongs in row 2 column 1. Name this range "location" (formula tab - define names option)
Step 2 - Decide where you want to hold the data (I'm assuming it is in sheet 4 for simplicity) And add the row numbers (1-4) and the column numbers (1-3) as labels. In my case the row labels are in A5:A8 and the column labels in B4:C4 (see the screenshot below). Then in the upper left corner of the values to be filled in (B5 in my case) enter the following formula (suitably adjusted to match your ranges):
=IFERROR(INDIRECT(ADDRESS(SUMPRODUCT(ROW(location)*(location = CONCATENATE($A5, "_",B$4))),SUMPRODUCT(COLUMN(location)*(location = CONCATENATE($A5, "_",B$4))),,,"Sheet1")),0)
and copy it over the intended range. Be careful with the dollar signs - this formula mixes row absolute and column absolute references in an essential way. Somewhat oddly, it actually works:

How to use VBA to color and frame cells with value

I'm trying to color and frame a column in data. There are blank rows inside. I only want to color the cells with value. The data position might change, so I want to use an input box to color and frame .
The data will be like this. The select range would be column B.
1 A
2 B
3
4 A
5 B
6
7 A
8 B
9
10 A
11 B
12
13 A
14 B
15
16 A
17 B
18
19 A
20 B
21
22 A
23 B
You don't necessarily need VBA - you could use Conditional Formatting. Highlight the entire column B, then go to "Conditional Formatting" under Home tab. Click "New Rule" and choose the last one in the list, "Use a formula to determine which cells to format.", enter this in the box =$B1<>"". Then click "Format" and go to "Fill" - choose the color you want, and hit "OK" and "OK". That should do it!
Edit: Ah, about the input box - can you expand on what you want to do with that? What do you mean by using it to "color and frame"?

A program that will return the cell address of the minimum value in a row?

So I have a chart that looks something like this. Assume that the top left value, 1, is in cell A1:
x= 1 2 3 4 5 6 7 8
4 3 2 1 2 3 4 5
9 8 7 6 7 8 9 10
8 7 6 5 4 3 2 1
Sum= 21 18 15 12 13 14 15 16
There are x values from 1 to 8, and a three columns of values resulting from using it an equation or something below it. The sum is the sum of the three values below their corresponding x-value.
I'm stuck trying to figure something out that will go through the row of sums, find the smallest value, and then assign it's corresponding x-value to a variable. I also need to assign the values to the left and right of that x-value to other variables.
For this particular chart, 12 is the smallest of the sums, so I would assign variable1 = 4, since that is that column's corresponding x-value. Then my second variable, which is called lowerbound, would equal 3, since it is to the left of x = 4, and my third variable, which is called upperbound, would equal 5, since it is to the right of x = 4.
If I could get the cell address returned of the x-value that corresponds to the smallest sum, then I could assign it to a variable, and then simply offset from that cell to assign the other variables. Even if I could make a program that will return me the cell of the minimum sum value, I could offset to the x-row, and go from there.
How would I do something like that?
TL:DR: To ask more clearly, since that's a lot of words: What would a program look like that detects the smallest value in the sum row, and returns the cell address of that value?
The length of the rows are an unknown, and vary a lot, but the length of the columns are given. They do change depending on the problem, but they will always be known. So I will always know how many rows are in a column, but I will not know how many columns are in a row.
This is the most confusingly-worded thing I've ever written in my entire life, but I hope I've explained it well enough to make some sense.
You guys really are amazing, by the way. I've gotten so far on this program, and it's all because of how helpful you are. I honestly think I would still be stuck at the beginning with you guys! You're willing to tolerate a newbie's incessant questions.
I am assuming that the sum is in A4:H4. Please change as applicable
You can use a formula like
=CELL("address",INDEX(A4:H4,MATCH(MIN(A4:H4),A4:H4,0)))
If you want to use VBA then you can use this
Sub Sample()
MsgBox Application.Evaluate("=CELL(""address"",INDEX(A4:H4,MATCH(MIN(A4:H4),A4:H4,0)))")
End Sub
Using your example, the following formula returns the cell address in row 1 whose value in row 5 is the lowest:
=ADDRESS(1,MATCH(MIN(A5:H5),A5:H5,0))
And if you want that cell's value, use INDIRECT. It takes the address as a string.
=INDIRECT(ADDRESS(1,MATCH(MIN(A5:H5),A5:H5,0)))
If you sum the columns by taking the sum of the array. Here is the VBA version:
For j = 1 To 8
For i = 1 To 3
sum(j) = sum(j) + Cells(i + 1, j + 1)
Next i
Cells(5, j + 1) = sum(j)
Next j

Display data table for a pie chart in excel using vb.net

I have an excel data and able to draw an pie chart from vb.net.
I should be able to add the data table below the pie chart from vb.net
Thanks
Rupesh
A very useful trick I learned a while back is if you open Excel, record macro and then step into it, you can usually see how to write the code or get something very close to what you'll need in .NET. For example, I created 4 columns like this:
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
I went to the Developer tab and hit 'Record Macro' and then highlighted the cells and inserted a table. I then hit 'Stop Recording" and stepped into the macro by selecting it from the Macros list. It gave me this code:
Range("A1:D6").Select
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$D$6"), , xlYes).Name = "Table1"
You should be able to do something very similar in .NET using the interop. There are range and table objects in .NET that you can use and place the table where you like.
Hope this helps.