Using a variable when setting a range - excel

I have created a variable loop to check a column for a value. If that column has a value I want to use that variable to set a range B & variable to F33.
So sArea is the variable
how do I replace this:
Sheets("DEVELOPMENT CONTROL").ScrollArea = "B1:F33"
To something like this:
Sheets("DEVELOPMENT CONTROL").ScrollArea = "B & sArea : G38"
which doesn't work

This should work:
Sheets("DEVELOPMENT CONTROL").ScrollArea = "B" & sArea & ":G38"
You need to pass sArea as a variable instead of text, like above.

Related

Add single quotes around a word in an excel column

Currently the text in a cell looks like this-
UPDATE A SET group_name = B WHERE group_ID = C;
Formula used for this is-
="UPDATE "&$N$1&" SET "&$N$2&" = "&TEXT($B2,"MM/DD/YY")&"WHERE "&$N$3&" = "&$E2&";"
I want to add single quotes around B here so that it looks like this-
UPDATE A SET group_name = 'B' WHERE group_ID = C;
How do I achieve this by tweaking the above mentioned formula?
As commented few methods here. All following formulas should work for you.
="UPDATE "&$N$1&" SET "&$N$2&" = "&TEXT($B2,"'MM/DD/YY'")&" WHERE "&$N$3&" = "&$E2&";"
="UPDATE "&$N$1&" SET "&$N$2&" = '"&TEXT($B2,"MM/DD/YY")&"' WHERE "&$N$3&" = "&$E2&";"
="UPDATE "&$N$1&" SET "&$N$2&" = "& CHAR(39) & TEXT($B2,"MM/DD/YY") & CHAR(39) & " WHERE "&$N$3&" = "&$E2&";"

VBA Dynamically Building A Formula From An Array

I am trying to dynamically construct a formula based on an array that I have generated from a cell (separated by commas), as there is a varying amount of elements in the array I need to append a new "formula block" with the updated element to use in a if statement that is generated after the for each loop. VBA is throwing a type mismatch error in the InvestigateFormula = line, here is my code:
For Each Type In ToIgnore()
InvestigateFormula = "(ISNUMBER(SEARCH(*" & ToIgnore(Type) & "*," & _
AssetTypesCol & "2)),"
FullFormula = InvestigateFormula & FullFormula
Next Asset
FinalInvestigateFormula = "=IF(OR" & FullFormula & "),""Ignore"", """")"
ActiveCell.Formula = FinalInvestigateFormula
Please let me know if there is an easier way of doing this or how I might be able to correct the above code. Btw I am not declaring a variant I am simply declaring ToIgnore() as String and using the split function from the variable which contains the comma separated values to generate the array/items to loop over.
"Type" is a reserved name? Try strType instead?

Using a string variable in Xpath syntax

I have a list of image names on Excel that I need to find on a website.
Can I use a string variable within the Xpath syntax to find all these images one by one through a for-next loop?
I tried this but it does not work:
dim bot as new chromedriver, variable1 as string
bot.get "http://xxxxxxxxxxxxxxxxxxxx.com"
For a = 1 to 10
varaiable1 = cells(a,1).value
bot.findelementbyxpath("//img[contains(#alt,variable1)]").click
next a
It does work when I use specific string value, say 'clean':
bot.findelementbyxpath("//img[contains(#alt,'clean')],")
Easy fix, variable1 is a... variable, so you must concatenate the values using &
bot.findelementbyxpath("//img[contains(#alt," & variable1 & ")]").click

How to convert part of a cell value to bold

I have the below VBA code and A and B are holding some strings. I want to concatenate these values with some other strings and store the result in a different cell, but I want only the strings in A and B to be formatted as bold and the rest as normal text.
Set A = Worksheets("Mapping").Cells(rowNumber, columnNumber)
Set B = Worksheets("Mapping").Cells(rowNumber, 3)
' E.g.: A="currency", B="Small Int"
Worksheets("TestCases").Cells(i, 2) = "Verify the column " & A & " has same Data type " & B & " in code as well as Requirement document"
Expected output:
Verify the column currency has same Data type Small Int in code as well as Requirement document
Note: The values of A and B keep changing, so we cannot use the Characters() function.
Any help will be highly appreciated.
You can use the Characters() method - you just need to keep track of the length of the substrings. Personally, I would store the static strings in variables so that I can change them later without having to recalculate the indexes by hand:
' Untested
Set A = Worksheets("Mapping").Cells(rowNumber, columnNumber)
Set B = Worksheets("Mapping").Cells(rowNumber, 3)
Dim S1 = "Verify the column "
Dim S2 = " has same Data type "
Dim S3 = " in code as well as Requirement document"
With Worksheets("TestCases").Cells(i, 2)
.Value = S1 & A & S2 & B & S3
.Characters(Len(S1), Len(A)).Font.Bold
.Characters(Len(S1)+Len(A)+Len(S2), Len(B)).Font.Bold
End With
The function to change the font style is:
[Cells/Cell range].Font.FontStyle = "Bold"
Therefore something like might work:
Worksheets("Mapping").Cells(rowNumber, columnNumber).Font.FontStyle = "Bold"
You can also make things have underlines, strikethroughs etc... I found this really helpful blog post which goes through everything you should need to know:
http://software-solutions-online.com/excel-vba-formating-cells-and-ranges/#Jump4
I think you should have searched for this information yourself... Nevertheless this is the code that you should use to convert some cell data to bold:
Worksheets("Mapping").Cells(rowNumber, columnNumber).Font.Bold = True

How to reference variables within a string on LiveCode?

I have a piece of code that I am trying to run, however I am trying to include variables as part of my string. This can be found in the line
put "A" into field "Field_(position)_(lettersinword)
The two asterisked words are the variables I would like to include. How do I do this?
global finalword
global lettersinword
global position
position = 0
on mouseUp
repeat until position = lettersinword
add 1 to position
if char(position) of finalword = "a" then
put "A" into field "Field_(*position*)_(*lettersinword*)
end if
end repeat
end mouseUp
You can use the string concatenation & in LiveCode but you also need to enclose the concatenation in parentheses:
...
put "A" into field ("Field_" & position & "_" & lettersinword)
...

Resources