VBA cell referencing and random numbers [closed] - vba

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I was having a play around with excel 2007 VBA and was hoping to create a Macro that generates a random number, then outputs a string based on the number generated. For example,
Number String
1 A
2 B
3 C
4 D
If the random number is 4, the output would be D.
I have a table of a similar nature in my Excel worksheet.
So far I have not had much success at doing this, any thoughts?

If all you need is to generate A - Z with equal probability then use =CHAR(65 + RAND()*26) directly on the worksheet.
It's always better to keep away from VBA as it makes spreadsheets more difficult to debug and since VBA works in a single thread, these days it can be a bottleneck.

Another way on worksheet, to deal with any string is to use
=CHOOSE(rand() * 4 + 1, "One", "Of", "Four", "Strings")

If you have a table as you say then you can use INDEX, e.g. if List is a named range containing a list of strings in separate cells you can use this formula to get a string at random
=INDEX(List,1+RAND()*COUNTA(List))

Related

Subtract Values in Two Ranges VBA [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am trying to write VBA code to subtract column A from column B. I want it to take the first cell in each range and do the math then output the resulting value in column C.
i.e. the output should look like:
Sub FOO()
[C1:C6] = [B1:B6 - A1:A6]
End Sub

SQL LIKE doesn't find obvious matches [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm writing the following SQL query:
SELECT *
FROM OS
WHERE OS.VERSION LIKE '%1%';
In my table there are rows with char 1 in it. However, it returns an empty result.
I changed a little bit the LIKE clause to different values, but it still doesn't work.
What can I do to fix that?
Try double-quotes and * for wildcards. You are using Oracle syntax instead of Access syntax.
LIKE operation can't be used with columns of integer type. I assume that OS.Version is of integer type?
Edit1:
If you are referring to MS Access then you have to do the LIKE with stars (*) instead of %.

Is there a way to remove specific characters from SQL Server Column [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a database table that contains a column for pricing.
Its very old, so it was written before i understood datatypes. so we are using varchar for a money value.
Ive noticed some columns have $ in them, so what I'm wondering is... is there a way with SQL Server to perform an update of the table and remove any instances of non numeric characters or at the very least remove the $ from the string in the columns in one go ?
I hope this is possible.
Update tbl
SET price = replace(price, '$', '')
Here is the replace definition

Rearrange the characters in a string alphabetically using SQL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am looking to take a string field and rearrange the characters into alphabetical order. For example, if it was a name field and the name was MICHAEL SMITH it would change to ACEHHIILMMST.
The main purpose is to look for duplicates in a field like name where someone could have made a typo and put in the name as MICHEAL SMITH or MICHAEL SMTIH. Another option I thought of would be to assign a number value to each letter (1-26) and then if the sum of those values and the length of the name field are the same it would be considered a duplicate. Problem with that is I do not know how to sum up numbers in a string field.
Also, I am using Oracle SQL so the functions would be based on those available.
Any ideas or at least places to start?
EDIT
I am not trying to ask for the code for how to do this, I am asking more if it is possible or not and if possible, what would my starting place be (types of functions, techniques, etc)
Check utl_match. It can be used to measure the similarity of two strings.
select utl_match.edit_distance_similarity('MICHAEL SMITH','MICHEAL SMITH') from dual
85
select utl_match.edit_distance_similarity('MICHAEL SMITH','MICHELLE SMITH') from dual
79
select utl_match.edit_distance_similarity('MICHAEL SMITH','FRANKIE JONES') from dual
8

Get me a SQL quesry to check whether the two table data contents are equal? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am having two table A and B of same structure.Both tables is loaded with data.I just want the mismatched row of two tables.,,
I'm certain you could do some gigantic JOIN query for each column and then issue a NOT IN over the result but a simple, pragmatic solution is to:
Write a query that orders the data on several columns (or all)
Export the query executed on each table to a separate text file
Use diff to compare the files with each other
Depending on the RDBMS vendor you may have other options you could consider as well.