Here's sample code:
set myExcelDB to {type:"excel", file:ResourcePath(testRunFilePath), name:"TestRun" ,writable: Yes}
put the records of myExcelDB into allTestRunRecords
repeat with each item of allTestRunRecords
put 1 into counter
put counter into currentRow.passed //why is this counter number not updated into my excel file?
end repeat
I had the counter values stored into the currentRow.passed field from the run window but the excel is not updated. Am I missing something?
I wanted to store to the current row's "Passed" column.
Solve it by using put first record of xxx
set myExcelDB to {type:"excel", file:ResourcePath(testRunFilePath), name:"TestRun" ,writable: Yes}
put the records of myExcelDB into allTestRunRecords
repeat with each item of allTestRunRecords
put the first record of myExcelDB where ("ID") is it.ID into currentRow
put counter into currentRow.passed
end repeat
Related
I am trying to set the table row height for the Word table row that contains the cursor in one of the cells in the row.
No text is selected; I click on a cell.
Here is my C# code that loops over all rows in the selection and adjusts the row height.
foreach (Row current in sel.Rows) {
current.Height = InchesToPoints(height);
}
The problem is that the code works if the selection contains multiple rows (click in a cell and drag down to a second row), but the code skips the loop if the cursor is placed in a single cell by clicking within the cell. I checked the value of sel.Rows.Count and it is 1 for the single row case, so I expect the loop to run once. But it skips the loop as if sel.Rows.Count was zero.
The selection.Type is selectionIP (in paragraph), and the selection is in a table.
Why would the loop work for two or more rows, but skip the loop when sel.Rows.Count==1? It's like the sel.row.count of 1 is not being treated as a row.
Maybe I need to programmatically select the entire row?
The selection.Type is selectionIP (in paragraph), and of course the
selection is in a table.
This is entirely to be expected. Your selection does not contain any rows as the insertion point has been placed inside a cell. As a result the selection does not contain any table elements.
They can, however, be obtained.
If Selection.Information(wdWithInTable) returns true Selection.Information(wdEndOfRangeRowNumber) will provide the row number.
You can then set the row height using:
Selection.Tables(1).Rows(Selection.Information(wdEndOfRangeRowNumber)).Height = InchesToPoints(height)
Okay - This has been asked multiple times, but asking again for best possible solution :
I have two excel files (not sheets). the first excel sheet is very huge and has close to 200,000 records. One of the column (Gender) is corrupted and i have to fix it.
I have a second excel file and it has only around 200 records - these have the correct value for those ones which are messed up.
for eg:
and this is the file that has correct values with only around 200 records (only the corrupted ones).
Now i need a macro , where i need to find these exact 200 records out of 200,000 records (by employee id) and replace the Gender value with correct one.
i found something similar here. but i dont want to loop 200,000 records 200 times. feels like a performance overhead.
is there a better option?
I am thinking an ideal solution would be
Loop through 200 items and use employee id per loop
Take that employee id and do a "Find" operation in the Employee id column of the master excel
If found, replace the Gender column value
would there be any other better solution? Any inputs is gladly appreciated
One way to do this through VBA is to just loop through the 200 corrections, comparing the ID with the MATCH function to find the row it belongs on, as opposed to a second loop (a second loop through 20000 would take ages like you say).
For the below sub I have copied and pasted the 200 table into columns 5:7 of the 20000 table, you can either automate this part easily enough, or just put in the correct sheet references for each part of the code.
I've also put in a checking line to make sure there IS a match for the current ID from the small table, otherwise it'd throw up an error. You could put an ELSE in front of the END IF in this error catch to highlight any ID's which weren't actually found. Here's the code, hope this method helps!
Sub replace_things()
With ActiveSheet
For x = 2 To 200 'Change this to however many is in the small table
cur = .Cells(x, 5) 'Defined cur as ID from small table
aMatch = Application.WorksheetFunction.CountIf(.Range("A:A"), cur) 'Check to see there's a match in large table
If aMatch > 0 Then ' if there's a match then...
theRow = Application.WorksheetFunction.Match(cur, .Range("A:A"), 0) 'get the row number the match is actually on
.Cells(theRow, 3) = .Cells(x, 7) 'when row is found, replace with the relevant value from col7 (col3 of small table)
End If
Next x
End With
End Sub
A super quick way, copy your CORRECT employee ID list and paste below the CORRUPT employee ID list... highlight duplicates and correct the highlighted.
Otherwise a VLOOKUP could label which ones are corrupt? basically getting a unique field from your correct list and comparing that to your corrupt list then fixing the ~200 errors.
I assume that the employee ID is a unique record so you can paste the correct ones under existing ones, sort by empID and highlight duplicates to find them easily.
I need help creating a excel macro to split orders based on qty column.
In the before sheet we have 4 orders with two of them having a qty greater the 1. see before macro image
What I need is an excel macro that can check the qty field and insert new rows below based on qty value if greater then 1, then populate these rows with the data from the original row.
Then the last step would be to delete the C column. See After Macro image
I have never used macros before, so i'm not even sure if this can be done.
It's only 10 lines of code. SO is not a code sweatshop where we do the work for you, it is one where we help you work it out for yourself.
This will poll the rows for you going backwards:
For X = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
This is key because you will be inserting rows, going forwards creates all sort of nastiness.
You will then need a loop inside there using your qty as a reference. Here is one I built but you will need to make some changes for it to work for your columns:
For Y = 1 To Range("B" & X).Value - 1
Then you need to copy row X inside this loop
Next line will be an insert with a shift down (like this Insert Shift:=xlDown) on row X + 1 or on an offset of row X by 1 row, your choice how you do this.
Last thing to do is delete column C, This can be done like this Range("C1").EntireColumn.Delete
That is it, the whole macro, just drop a couple of nexts and an end sub and run it.
You will need to Dim X and Y, dim them as longs.
Have a go, if you get stuck post back with the code you have put together and we can help you fix it.
I am trying (using VB) to copy 7 values from 1 location to another.
(copy from F115 to F134.)
(F115 is source of numbers; F134 is destination for numbers)
If there is data (any data) in F134 I want to advance the row by 1 and then print/copy. I do not want to overwrite any lines of data.
So, if there is data in the first row (F134) then I want to move/advance the row count by 1 and then copy the values into row F135 - and so on. It's possible that there could be 500 to 100 rows of numbers and I need to be able to view all of this data.
So far, this is the code I have: some works, but it does NOT advance the row count and continues to print into Cell F134. (oh yes, F124 is just a set of empty cells.)
Ok, this is my code;
Sub dbtest4()
Dim RowCounter As Integer
rowCounter = 1
Do Until rowCounter = rowCounter +1
'trying to advance the row counter by 1 such that if there is data in F134, the line count will advance and the new data will print into the NEXT line. (which would be F135)
'the following code probably is unnecessary, but I'm trying anything...
'actually the following code works ok: Range("F134").Resize(1,7).Value = Range("F115").Resize(1,7).Value, but that's about it.
If Range ("F134") = 0 then
Range("F134").Resize(1,7).Value = Range("F115").Resize(1,7).Value
'trying to print data cells from F124 if there is no data in F134
Else
Range("F134"),Resize(1,7).Value = Range("F124).Resize(1,7).Value
'trying to print the zeros or blank numbers from F115 if F134 has data in it
End if
Loop
Exit Do
End Sub
Thanks to anyone who may be able to offer some assistance.
So right now the exit condition for the Do While loop is that rowCounter has to increment by one. I can't see a reason why this should fail and that is why it is only happening once. Here is some psuedocode:
Do Until copiedVals = 7 'Or whatever exit value you want
If row.Value.Exists() then
'There is a value in this row, so increment the row count
rowCounter = rowCounter + 1
Else
'This row is empty and you can do your thing
'rowCounter will have the current row value
copiedVals = copiedVals + 1
End If
End Loop
I Need to use a loop in my code and at a certain condition I will insert row.
Rowz = activesheet.Cells(Rows.Count, 1).End(xlUp).Row
for j=3 to Rowz ' say number of rowz=1000
But as rows are inserted in between So the number of rows are increased. Say for example at the 200th row I insert 4 rows and 500th row I insert 10 rows So the number is increased to more than 1000 now so the loop tests till 1000 ignoring the remaining rows which are pushed down due to inserting. But I need to perform that loop till the last row even rows are inserted in between
I thought to use these
for j=3 to activesheet.cells(Rows.count,1).End(xlUp).Row
But the value is not updating i Guess its just checking upto 1000 only its not updating the number of rows value in the to condtion.
How do I count number of rows and keep it in a condition if rows are created in between?
Why don't you try looping backwards ? for j = rowZ to 3 step -1.
Might that solve your problem ?
Edit: option 2, you could define a name for the cell after the last one, and refer that Named Range: Range("myLastCell"). It will adjust every time you insert rows....
You might try to loop through a range:
Sub LoopRange()
Dim cell As Range, Rowz as Long
Rowz = Activesheet.Cells(Rows.count,1).End(xlUp).Row
For Each cell In Range("A1:A" & Rowz)
'do things
Next Bcell
End Sub
Warning: the vba will parse the whole range, including the inserted rows, so if you insert a row on every loop, your procedure will loop indefinitely (note, you can use Ctrl+Pause to stop the execution of your code if it happens)