How do I extract only the available active cell values into a collection? I've got an excel file that has 10 cell values but the blue prism process is reading is entire rows from the excel. Thanks in advance.
Well, to do that you'll need two actions:
1) The action that will return the active range
2) Action: "Get Worksheet Range as Collection"
The first action is not supplied out of the box, in standard "MS Excel VBO", but the code is really simple to write. It's should be just a code stage with one line of code
input: handle as number, Workbook_Name as string
output: range as string
x = GetWorkbook(handle, Workbook_Name).ActiveSheet.Selection.Address
(Disclaimer: I haven't tested that code)
The second one action is I think standard one, so you should be able to find it in your object.
Related
Hy everybody.
I'm trying to control the value of some cells through a reference page …
'On "TRAITEMENT" sheet
=NB.SI('refSheet'!A:A;'MyFirstPage'!I3)
So far so good.
However the name of the page which contains the cell to be checked ('Myfistpage') is not sure. It can change his name and some new sheet can appear between my pages.
I am sure, however, that my maximum page allowed is 15 and that they must all be processed.
I would therefore like to do a treatment for each page according to their index.
I try this code:
=NB.SI('refSheet'!A:A;feuil1!I3)
But the answer is always 0 regardless of the control performed ...
At all, I had to find a method to select a pages without using his name.
Thank all in advance for your answers.
You can create a User Defined function in VBA:
Function SHEETNAME(ShNum As Long) As String
SHEETNAME = Sheets(ShNum).Name
End Function
Then you can use the above function anywhere in your Excel workbook
=NB.SI('refSheet'!A:A; INDIRECT(SHEETNAME(1)&"!I3"))
i implemented a normal 'for each'-Loop (not the excel specific for each row) in my UIPath Project.
The for-each Loop looks through a datatable with previously retrieved data from an excel file.
The for-each-loop then itererates through the Data with an if-else behind it.
Lets say it is as follows:
for each item in dataTable:
if (content of item == "10")
{
write cell: "Test" into A + index.ToString()
// leads for instance to writing into excel column 'A1'
}
else
{ write cell: "ElseTest" into for C + index.ToString() }
-- I used the syntax just for presentation-purposes.. :D
-> So the problem is:
writing into the cells takes so much time, where else putting out a MessageBox with random text inside the if and elses is done in milli-seconds, so the for-each-loop can't be the problem...
I ran that process with task manager opened and found out that Excel starts up, CPU percantage increases heavily, immidiately jumps to 0%... same happens again, for each iteration through the loop.
Why is that?
Is there a more optimised way to do that?
I need the for-each structure, because I need to check if it's either value 1 or value 2 inside the cell...
One possible option is to use the Read Range activity, manipulate the DataTable object itself, and then at the end write said object back to the same range using the Write Range activity.
Here's an example. My sheet contains 100 rows with all numbers from 1 to 100 in column A. Whenever there's a "1" in the cell, the data will be overwritten (in the DataTable object).
I think opening excel on each iteration is the time consuming part so I suggest
open excel before your for each
use attach window activity (https://activities.uipath.com/docs/window-scope) inside your foreach to set focus on excel file
close excel after your foreach or when you are done with the excel file
I would strongly recommend reframework (https://github.com/UiPath/ReFrameWork/tree/master/Framework) if you are not using it. It is an excellent starting point for RPA projects.
If you are using reframework you can open your excel file in InitAllApplications.xaml do your operations in Process.xaml and close your excel inside CloseAllApplications.xaml.
I am new to this forum and I am seeking help with creating a function in Excel for data logging purposes. Basically I am trying to use Excel to write a macro simply by pressing "x" in certain cells. For instance, from cells A3-A6 I will have client's names listed there. In addition, I will have dates (of service) listed on the 2nd cell row and on.
9/20 9/21 9/22 9/24
John Doe x
Sara Mitchell x x
Christopher Acha x
Now, I have the macro, I have everything I need in order to set this up. The only problem I am having is to make Excel write the macro for me. I am trying to use the IF=() function, but it limits me to 255 characters, and it tells me to use the concatenate function. All I am trying to do is basically tell Excel that if a certain cell IS true, I would mark it by hitting x; meaning that if a person came on the 24th for service, I would hit x and from there excel would automatically write what I tell it to (in a different sheet or cell). I am stuck here, any help would be greatly appreciated.
You said you have a macro that works, so I'm assuming you want to know how to trigger it automatically when you enter data into a cell.
In your worksheet code use a change event and call your macro from here and pass the range you sent.
Private Sub Worksheet_Change(ByVal Target As Range)
myMacro(Target)
End Sub
You'll probably want to add in additional code to test that the cell changed is within a certain range before calling your macro.
Sub TEST()
If cells(i, "R").Value <> "UK" Then
cells(i, "R").Interior.ColorIndex = 3
End If
End Sub
If I run this program it throws application defined error \
I am new to Excel (beginner)
How to correct this error!!!
Thanks In advance
I think the issue is "R" that I know of the cells method takes 2 parameters one is rows the other is columns (in that order) but this is done by number not letter so if you change it to cell(1,18) then the code above works fine.
This link may also be useful to learn more, among other things it describes how you would normally select a range first as I believe your code above will assume the currently selected page, however you might want to run in on a button click from another page or as soon as the spreadsheet opens.
http://msdn.microsoft.com/en-us/library/office/ff196273.aspx
The problem is that the variable i has not been assigned a value. VBA assumes that it is zero. Since i is used to determine the row of the cell, Excel throws an exception because there is no row 0!
First you have to define i variable
for example: Dim i as variant
I have an Excel sheet that draws data from other, closed Excel workbooks. Currently it works fine when I list out the closed workbook's entire path, but I'd like to use a variable, stored in a separate cell, as part of the path name.
For example, I am trying to reference a workbook called
workbook12.10.12.xls
In a separate workbook (we'll say the "active" workbook), I have a cell with formula
=INDEX('C:\Path[workbook12.10.12.xls]SHEET1'!$B$1:$B$5, MATCH("match text", 'C:\Path[workbook12.10.12.xls]SHEET1'!$A$1:$A$5, 0))
which finds the value in workbook12.10.12's B column corresponding to the cell in the A column that contains "match text." This works fine; however, I have a cell in the active workbook with the value
12.10.12
and would like to somehow reference this value in the INDEX function.
I can't have the other workbooks open, so the INDIRECT function won't help. Googling seems to suggest that Excel doesn't have a simple one-stop solution for this kind of thing... can someone help please? Thanks!
From Frank Kabel's 2004 post at Dicks Blog you could
Use Laurent Longre has developed the free add-in MOREFUNC.XLL which includes the function INDIRECT.EXT
Use SQL.REQUEST as described here *does not appear to be supported anymore and I am not clear if this could handle your INDEX\MATCH request
Use Harlan Grove’s PULL function
In addition you could:
Create a "dirty link" directly via code that enters a formula referring to the workbook you need
For pulling values - but not for working with ranges - you could use Walkenbach's ExecuteExcel4Macro XLM method
I think what you what to do is to find the specific record in the specific file (date named).
You may do it by a simple VBA code.
Suppose you are going to search for a record# say REC001 in A1, date file 12.10.12 at cell C1, and have the result to be display at cell A7
On the worksheet you want to enter input and get output, rightclick the sheet tab and select 'View code' and paste the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C1")) Is Nothing Then Exit Sub
Range("A7").Formula = "=INDEX('C:\TEMP\[workbook" & Range("C5").Value & ".xls]SHEET1'!$B$1:$B$5, MATCH(" & Range("A1").Value & ", 'C:\TEMP\[workbook" & Range("C5").Value & ".xls]SHEET1'!$A$1:$A$5, 0))"
End Sub
Then every time you edit C1, the formula will be updated.
Actually I don't think you should use INDEX function in your case. It is more simple to use a VLOOKUP. E.g.:
Range("A8").Formula = "=vlookup(" & Range("A1").Value & ",'C:\TEMP\[workbook" & Range("C5").Value & ".xls]SHEET1'!$A$1:$B$5,2,false)"
You will have to note on a few points:
1. you paste the code on the Sheet1 object (or the sheet name) but not to insert a new module
2. your path and filename for the target file is correct, including the .xls and .xlsx
3. your original file only cover to $B$5
4. on VBA, recommend you to save the file as .xlsm format
You can store a full reference including the file path to a range in a closed file in a name in excel (either directly or via VBA based on selections in different cells and using the Worksheet_Change procedure as above) and then refer to the file using the name in a formula as normal. This gets over the limitation in the INDIRECT function.
The VBA is very simple:
New_Ref = Sheets("Wells").Range("K6")
ActiveWorkbook.Names("MyWorkbook").RefersTo = "=" & New_Ref
The only trick is to be sure to include "=" in the name.
Names have a huge number of uses once you spot this. I have used this to get data from a closed file on a remote sharepoint site without any difficulty - I assume sharepoint deals with all the permissions.