vb.net check the value of each column for only the 1st row datatable - vb.net

I want to check the first row only of a data table. I want to verify that the right name is in the right column. The first row has header name and they have to be in the right order. for example I want to check the first row and the first column to check that it has "First Name"
If I do the following it give me the right column data but it gives me the 2nd row not the first. I don't get it since I am asking for row 0 and col 0.
Dim ExcelData As DataTable
field = ExcelData.Rows(0)(0).ToString()
(actually I will want to do a IF to check this column. first wanted to see what value is there before I code it all )

Related

Reference another cell in a different row having calculated the minimum value in a datatable column

Reference another cell in the same row having calculated the minimum value in a datatable column
The above answered my question as to how to reference another cell in the same row having calculated the minimum value in a datatable column. But how do I reference a cell in another row still using that original cell?
In other words, if the min value in a column is in row 5, I now know how to get the values of cells in all other columns within row 5, but how do I get the values from columns within other rows (eg row 6) using the original cell as a starting point?
Dim Data() As DataRow = datatable.Select("sourcecolumn = " & test.ToString())
Dim column2 = Data(0)(1)
was the answer to my first question, how would I amend this to get to another row? I tried:
dim column2 = Data(1)(1)
but it returns an array error. I think the numbers in brackets are absolute, but I need to use relative ones.
Thanks in advance again.

How to lookup if my lookup data has duplicate values?

I am trying to lookup values from Table 1 to Table 2 based on Col1 in Table 1.
The catch is that Table 1 has duplicate values (for example, A is repeated 3 times) but I don't want to duplicate the returned value from Table 2.
How can this be done through either excel or sql (e.g. LEFT JOIN)?
What SQL are you using? Are you familiar with CTE and partition?
Have a look here: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/597b876e-eb00-4013-a613-97c377408668/rownumber-and-cte?forum=transactsql
and here: (answer and 2nd comment): Select the first instance of a record
You can use those ideas to create another field that tells you whether the row is the first, 2nd , 3rd etc occurrence of Col1. Eg you'd have something like
1 B Red 150
2 B Red 150
and you can then update col3 to be zero where this new field is not 1.
EDIT: since you asked about Excel: in Excel, sort by whatever criteria you may need (col 1 first, of course). Let's say that Col1 starts (excluding the heading) in cell C2. Set cell B2 =1. Then write this formula in cell B3:
=IF(C3=C2,B2+1,1)
and drag it all the way down. This will count the occurrences of col 1, ie it will tell you which is the first, 2nd etc time a given value appears in col1. You can then use it as as the basis to change the value in other columns.
Also, it is not good practice to have a column where the first cell has a different formula from the others. You can use the same formula nesting another IF and referencing the row, so as to set one formula for the first row and one for the others.

Adding a row between cell with the same value using VBA code

Im new in VBA and want to know how can i format my table in such a way that each name in Column one do only have 1 row in between.
Some of them do have more than 1 row in between and some of them doesn't have. I just need to format then in such a way where every name on column A has 1 blank row in between. Any help would be appreciated!
Please note that i have thousands of data so manual will not work.
also i tried doing the filtering and convert them into single block. the problem with single block is that my column c do have more than 1 information which is connected to column a, .
here is an example.enter image description here

Adding 1 to existing number in a cell based on value of another cell

Alright so I looked through for other solutions but I didn't get anything close enough with my limited knowledge to make it work so I hoping some geniuses here can help.
Basically I am using excel to autoupdate some data based on the value of another cell. A simplified version of my table looks like the below:
ID Step Count
526985 - Step 1 8
123569 + Step 3 3
589745 - Not in AMP 1
589465 + Step 2 5
IDs are unique and always 6 digits (just fyi if that helps anything). There will never be a Step column or count column value without an ID value
I would like to use the change val in vba so it changes as I go along automatically
The goal is for the user to not have to update manually the value in the "Count" column
When the user starts working on the sheet, the "Step" column will be blank and will be selected from a drop down menu but the "Count" and "ID" will be populated already
What I need:
When a value of "+ Step 1", "+ Step 2", "+ Step 3", "+ Step 3 ext", "- Step 2", "- Step 1" is selected in the "Step" column for an ID, I need "+1" added to whatever the current value is in the "count" column
When a value of "- Not in AMP" is selected from the "Step" column, I need the value to be 0 in the "Count" column
There will be other values selectable from the "Step" column which I need to be ignored (Keep the same "Count" column value)
After a step value has been selected in the "Step" column and the "count" column has been updated. I still need to be able to go back and change that value to any other number manually.
I think that's about it. I thought of using formulas which I could do but the issue is where I need to be able to overwrite the value with another, it will delete the formula. I'm open to anything that makes this work though. Thank you in advance!
After you have a Change event you could have some logic to check:
- if user is adding a new value in the correct column, you would load the previous data into a variant to perform the logic that you have given to populate the addition cells
- if not, let the user update the values.

table get the cell from the row

I have one table with 3 rows and 3 columns. Now I want to add 2 row's 2nd columns cell's control. That means whether that is text or combox in the cell. How do I get the 2nd row's 2nd column and remove the compoenent dynamically in SWT JFace?
Do you use a TableViewer?
The SWT-way of getting to the item is indexed first by row, than by column.
Getting the text of the third column in the second row is done like this:
table.getItem(1).getText(2);
To display custom-controls, like a combobox you will have to either paint it manually or use SWT's TableEditor.
Also check out this tutorial: http://www.eclipse.org/articles/Article-Table-viewer/table_viewer.html