I have a datasheet that looks like this:
ID name_ 1 2 3 4
1 name1 x 0 0 0
2 name2 0 x 0 0
3 name3 0 0 x 0
4 name4 0 0 0 x
I have rectangles on a report that correspond to this datasheet.
When the report opens, I need the rectangles to be colored red according to the data. For example, in the name1 row where there is an x in the 1 column, I need the specific rectangle corresponding to this (name1, 1) to be colored red. Here is the result that I need:
x
x
x
x
(where x is a rectangle that is red)
Perhaps the best place to place this code would be in ON LOAD event of the report, but i am not sure exactly. Can you please suggest to me some code that would turn the specified rectangles red according to the data?
Use conditional formatting, not code.
In this case, I see no reason that #Remou's answer is not correct -- you want to display an x, which is data, so you would use a textbox with conditional formatting that sets the background color appropriately.
However, if you wanted to do this without a data control, you'd likely use the Format event of the Detail of the report. This is the event that fires when each record is processed, and it could be used to run a test that determines which rectangle to hide/show or what color to give the background of the rectangle.
The OnOpen runs before any of the data is loaded, and the OnLoad event before any particular rows are accessed. Because of that, neither is appropriate for formatting controls in individual rows of the report.
And BTW, your mention of the OnLoad in reports indicates that you're using Access 2007 or later (the event didn't exist for reports in A2003 and earlier), and you should have stated that in your question.
Related
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
I am creating a StackedArea chart in VB.NET and I have some data rows which contain all 0 but one value which is for example 10.
When I draw these values, I loop over all these values, draw a zero and then continue with the next point. An example data row looks like this:
"january",0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.03,0.10,0.00,0.00,0.67,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
As one can see in the in the blue line, there is still something (let's say 1px) displayed, even if the values are all 0.
My code to draw these series looks the following:
Chart.Series.Add(item(1))
For i = 2 To 25
Dim cell = worksheet.Cells(item(7), i)
Chart.Series(k - 1).Points.Add(cell.Value)
Next
Chart.Series(k - 1).ChartType = SeriesChartType.StackedArea
Chart.Series(k - 1).BorderWidth = 0
Does anyone have any idea what is going on? Thanks in advance.
I have 2 sets of coordinates in a table. The first set is XFrom and YFrom and the other set is XTo and YTo. If you draw a line between these two coordinates then you get an arrow.
I would like to draw these arrows in a report, for as many rows as the table has.
XFrom YFrom XTo YTo
1 1 3 3
2 2 4 4
1 2 5 6
Each row represents an arrow
I can't seems to find a way.
Any suggestions?
Thanks
Drag and drop a chart control from the toolbox.
As soon as you do that , you get a pop-up, displaying various image shapes for the chart control & try to choose your option.
I have an application that keeps rent periods of a parking lot. I have a SQL database with this information:
idLot dateFrom dateTo
------------------------------------------
1 01/03/2011 30/07/2011
2 01/01/2011 30/05/2011
3 01/02/2011 30/07/2011
6 01/02/2011 30/06/2011
And I need to display the information like the image below.
1
I cannot achive the goal with Excel or Crystal Reports. I also use ComponentOne FlexGrid. Any ideas?
Thanks in advance.
It's not the prettiest option, but you can do this in Excel using the Sumproduct() function. In the screenshot below, the sumproduct goes through each line of your datatable and does 3 things (the selected cell is B17 by the way):
It determines whether each row has the idlot it is looking for (evaluates to true/false)
It determines whether DataFrom is <= the column of your display table (evaluates to true/false)
It determines whether DataTo is >= the column of your display table (evaluates to true/false).
This results in a 0 or 1 in each cell of your display table. This is close, but not exactly what you're looking for. I then added some conditional formatting:
If the result of the equation was 0, then the cell's font is white.
If the result of the equation was 1, then cell's font and background are both green.
When you apply the conditional formatting to the entire graph, you get the last 2 rows, which is green for occupied and white for unoccupied.
The only remaining problem is how to account for a changing number of rows in your table. This can be solved by just setting the ranges in your equation to a very high number.
I am new to VBA and I am struggling trying to make this work. I am in need of a macro that will process each cell\column on Sheet1 and put the results on Sheet2. I'm sure this is pretty easy for those who are more advanced with VB code. It contains many columns..
Anytime we encounter a — or an empty cell, we populate the cell with -999 (see the example on Sheet2) on the first column, which contains "0-2". Then we create 2 new columns and populate them with 0 on the first column and 2 on second column (see example on Sheet2). If a value is found on only one side, we then populate both sides with the same number.
As each column is being process in Sheet1 and
Sheet1:
A B
Column1 Column2
Title Title2
0–2 0–4
3 —
— 5
—
— —
10–23 11—29
And the results should look like this on Sheet2
Sheet2
A B C D
Column1 Column1 Column2 Column2
Title-A Title-B Title-A Title-B
0 2 0 4
3 3 -999 -999
-999 -999 5 5
-999 -999 -999 -999
—999 -999 -999 -999
10 23 11 29
You don't really need VBA to do this. It can all be done using the if function.
Column 1 would use something like:
=IF(ISNUMBER(Sheet1!A2),Sheet1!A2,IF(OR(Sheet1!A2="-",ISBLANK(Sheet1!A2)),-999,LEFT(Sheet1!A2,1)))
Column 2 would use something like:
=IF(ISNUMBER(Sheet1!A2),Sheet1!A2,IF(OR(Sheet1!A2="-",ISBLANK(Sheet1!A2)),-999,RIGHT(Sheet1!A2,1)))
3 and 4 would use the same as 1 and 2 just shifted over a column.
Okay, your task is basically multi-part:
1 - Traversing a sheet with smart logic
2 - Splitting
3 - Placing data in new cell
This isn't proofed for working but this should give you the ammunition to accomplish your goal with minor effort.
Sub mySub()
dim i,j,dummy,dummy2, blankCounter
i=1
j=1
blankCounter=0
'######Section1
do while ThisWorkbook.Worksheets(1).Cells(1, j)<>""
do while blankCounter<=5
if ThisWorkbook.Worksheets(1).Cells(i, j)=""
blankCounter=blankCounter+1
else
'######Section2
dummy=Split(ThisWorkbook.Worksheets(1).Cells(i, j),"—")
for k=0 to Ubound(dummy)
ThisWorkbook.Worksheets(2).Cells(i, j+k)=dummy(k)
next k
end if
i=i+1
loop
blankCounter=0
j=j+1
loop
end Sub
okay, in english. Section one is looking at this workbook ("this" appearing commonly especially in java but this is a more palpable example of such logic). In this workbook look at my first worksheet. In this worksheet lets look at col1,row1. Now we are going to loop down the rows and keep going until they are blank, do the same with the columns. This will basically find the dimensions of your matrix (data).
Okay, so now that we can traverse the workbook we are half way there.
Now you get to know the Split functionality in VBA that also exists in almost every language. Split looks for something in your String and breaks up your string by the argument you supply. Dummy will hold whatever the return values are. The size of dummy is unknown, so we should not hardcode this otherwise it will break when the splitter is not present.
That being said, we now introduce Ubound. Ubound is a functionality that finds the size of your array. Note on this: if Ubound returns 1, this means you have one value. Arrays are auto indexed to 0 so you must note this and not loop from 1 to Ubound, this will give an error and also produce incorrect code.
Okay, good now that we can traverse our array and our workbook now we just need to put these values in the cells desired. var k should be able to do this for you.
As i said i haven't proofed this code, so you are going to need to make sure that this logic functions properly, as i realize now that it does not wrt placing the data in the correct cell, but this will be yours to solve.