I am new to selenium VBA and I am using selenium web drive to find the member's name in the web page and update the information for that record.
I can search the name and click the record by using the below code:
bot.FindElementByXPath("//*[#class='x2h' and text()='Peter
Melo']").Click
I would like to replace Peter Melo by using the Excel spreadsheet and Peter Melo is in the ActiveSheet Cell A1
So I tried to replace Peter Melo ActiveSheet.Range("A1").Value by using the above code but it doesn't work.
May I know how can I use the name available in Excel and search it in the Web?
Thanks in advance for any help or advice I might receive!
Can you try using
Sheet1.Cells(1, 1).Value instead of ActiveSheet.Range("A1").Value .
Range method usually used for a Range.its not the right approach to pass the single cell value.However ActiveSheet.Range("A1").Value should work. but if its not working then I assume in the active sheet it might not have any value. Can you try
Worksheets("Sheet1").Range("A1").Value
Where Sheet1 is the Sheet where you store "PeterMello".
But this should definitely work Sheet1.Cells(1, 1).Value
Your code should be
bot.FindElementByXPath("//*[#class='x2h' and text()='"+Sheet1.Cells(1, 1).Value+"']").Click
or
bot.FindElementByXPath("//*[#class='x2h' and text()='"+Worksheets("Sheet1").Range("A1").Value+"']").Click
Related
Please help me with the code to insert a column in excel using vba. Here is what I am doing -
Sheet1.Range("A:A").EntireColumn.insert
That code works fine for me.
Sheet1.Range("A:A").Insert works also. Range("A:A") is already referencing an EntireColumn.
There are a few things to check if it's not working for you:
You're referencing an object called Sheet1. Is that definitely the codename of the worksheet you want to change? Make sure you understand the difference between sheet name and codename. You could try referencing it by the sheet's name instead: Worksheets("Tabname").Range("A:A")...
Is the worksheet protected? That would give you an error if it is.
Is there any data in the right-most column of the spreadsheet? That would also cause an error as Excel doesn't know what to do with it. If you're not 100% sure, select the entire right-most column of the sheet and hit delete to remove anything that might cause an issue.
Lastly, can you insert a column manually? i.e. select left most column, [right-click] and [Insert]?
I think you got the Sheets property wrong, this works for me :
Sheets(1).Range("A:A").EntireColumn.Insert
You should clearly mention what you are trying to do; what type of problem you are facing.
However, you should try out the below code. hope this will help
Sheet1.Range("A:A").EntireColumn.Insert Shift:=xlToRight
while inserting a new row or column make sure to refer to the entire row or column. Check if there are any marge cells at the right of column A. That can possibly be causing the problem.
Sub TryMe()
Columns(1).Insert
End Sub
Also, this is a very generic question. If you can Google something and figure it out in a fraction of the time that it takes to craft a question and post it on SO, just Google it. If your question is very unique, and after hitting multiple dead ends using Google, then ask the SO community. I found the 3 links below using a Google search that took around 1 second.
https://www.automateexcel.com/vba/insert-row-column/
https://excelchamps.com/vba/insert-column/
https://www.educba.com/vba-insert-column/
I need to make a VBA which copy a cell into a cell in another sheet. (Same workbook).
Afterwards i have to create a pdf (i have VBA for this).
After the pdf creation, i need do this all over automatically and i would like to have a VBA for this. Because i need to make 200 pdfs
My question is therefore:
How can i create a VBA which copy a cell from a list i sheetB to a cell in SheetA, and after the creation of the pdf, do it all over with the next cellvalue from sheetB? I guess it is something with the "looping" tool?
A good way to create basic VBA to automate standard tasks it to record a macro while you perform the steps. Afterwards, you can view the VBA that was generated for the macro, automate it further as necessary. Here's some instruction and examples:
Getting Started with VBA in Excel 2010
Recording a Macro to Generate Code
Revising Recorded Visual Basic Macros
I'm not aware of a "looping tool" but there are various ways to loop through data with Excel.
Edit:
Looping through a list is the easy part. For example, the following code pops up a MsgBox with the value of each cell in range A1 to A15:
Dim cel As Range
For Each cel In Sheets("Sheet1").Range("A1:A15")
MsgBox cel.Value
Next cel
Get your VBA together for doing your task once, add the code to your question, and then we can stick the loop in the correct spot.
I am trying to accomplish something apparently simple but not for me. I’m new to all this and I would like to see if I can get any far with this first project. Basically I have, say 3 text boxes with a string in it (name) and a button next to them. Then there is another text box which will hold all 3 names so that I could copy as one string into clipboard. Many tutorials out there refer to concatenating the strings however I’m still unable to find a decent answer. To be fully honest I am trying to achieve this task in VBA from within Excel 2010. So, my 3 names are actually in 3 different cells… Next to each of them I have a button with a macro attached (but vb will also be good for me) that will add the name into another cell. The buttons works ok but my problem is that I can’t get them to concatenate in Excel. Every button just overwrites what’s was there before. Any help? Suggestion? Tips? Mind you I can only be able to follow if the answer is simple and well explained as I am new to all of this. Thank you.
If you had 3 strings in A1, B1 and C1, you could get the concatenated string in D1 by putting in the formula `=CONCATENATE(A1,B1,C1)' in the cell D1. If you want to do it in VBA,
Public Sub MyConcatenation()
With ThisWorkbook.Worksheets(1)
.Cells(1, 4).Value = .Cells(1, 1).Value & .Cells(1, 2).Value & .Cells(1, 3).Value
End With
End Sub
If you won't take offense: You need to pick up an introductory book or website to learn VBA (it is not VB or VB.Net). It will be a long, uphill struggle to learn it through asking questions on forums.
I want to set the following formula(its already working fine) in first 1000 rows in excel.Actually I am looking in VBA. But, I am not familiar in VBA code.
=IFERROR(VLOOKUP(DD,HDR_COLMN,COLUMN(),0),"")
DD - getting data from another sheet
HDR_COLMN - getting table header from another sheet(Sheet2) and showing as drop down values in Sheet1
Please any one can help me. Advance thanks
The only tricky part is the double-quotes.
Say we want to deposit this with VBA
=IFERROR(VLOOKUP(A1,B1:C10,2,TRUE),"")
This will do it:
Sub luxation()
Range("A10").Formula = "=IFERROR(VLOOKUP(A1,B1:C10,2,TRUE),"""")"
End Sub
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.