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 trying to manipulate a text in excel using vba. The text I am tyring to manipuate look like the following two texts:
text#1: ...54
text #2: ..2
I am trying to remove the dots from these texts so that only the number(s) remains, as follow54
text#1: 54
text#2: 2
Please advise.
This is how it works:
Sub ReplaceDots()
Dim col as Integer
col = 2 'The Column where you want to replace the dots
For Row = 1 To 20 'Define the Range here
Set curCell = Worksheets("Sheet1").Cells(Row, col)
curCel.Value = Replace(curCel.Value, ".", "")
Next Row
End Sub
edit: maybe i switched rows and columns, you have to test
Have a look at the Replace function.
Replace ( string1, find, replacement, [start, [count, [compare]]] )
string1 is the string to replace a sequence of characters with another set of characters.
find is the string that will be searched for in string1.
replacement will replace find in string1.
start is optional. This is the position in string1 to begin the search. If this parameter is omitted, the REPLACE function will begin the search at position 1.
count is optional. This is the number of occurrences to replace. If this parameter is omitted, the REPLACE function will replace all occurrences of find with replacement.
compare is optional. This can be one of the following values:
vbBinaryCompare Binary comparison
vbTextCompare Textual comparison
vbDatabaseCompare Performs a comparison based on information in your database
http://www.techonthenet.com/excel/formulas/replace_vba.php
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am completing an NEA for my GCSE assessment, and need help with a certain piece of code.
The task requires me to create a music quiz in which the Artist of the song and the first letter of each word of the song title is displayed. I don't know how I would even start to do this. Currently I have the songs in an array from an external file and can output a random one based of a random number generator but need help manipulating the string.
Any help would be much appreciated,
Thanks.
You can read each character individually in VB.NET by accessing it as if it were an array. So if you have for example:
Dim s As String = "abcdef"
Then if you use brackets like it is an array you can return a single character.
So to get the first element would be:
Dim first_letter As String = s(0) ' This would return just "a" as it is the first item and arrays are 0 indexed
And to find each element you can do s(1), s(2) etc or whatever your string is called as a string is an array of characters so they can be accessed and manipulated like one.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am new to VB.net and I want to check a text box is not null or empty
I have used so many ways to find out
But none helped me out
These are the methods I have used
If textbox1.text.trim.Length >0 then
My sql insert query
End if
If textbox1.text<>"" then
End if
Could you help me out where I am going wrong
Since you are using Trim - for removing white spaces - there is another method which will fit your requirements:
String.IsNullOrWhiteSpace Method (String)
Indicates whether a specified string is null, empty, or consists only
of white-space characters
If String.IsNullOrWhiteSpace(textbox1.Text) = False Then
' your MySql query
End
Actually both of your approaches should work too.
In Winforms textBox.Text will never be null, so checking for .Length after trimming should work.
You can use both of them:
1 :- String.IsNullOrEmpty(yourString);
1 :- sNullOrWhiteSpace(yourString);
For more details visit the LINK
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to use a number in a cell of my main excel sheet and use it to search for a specific line in another excel file that start with this number. After, the program needs to use the value of a specific cell in this line for a cell in my main excel sheet.
EX : value of the first cell in my sheet : 6.02 . Now the program need to find this value in a column of another file. The line that start with 6.02 contain a cell with the value dog. The value dog need to go inside a cell next to the first one that contain 6.02.
I need your help because I know nothing about VBA. I'm starting today!
Thank you very much !!
You can accomplish this with a VLOOKUP between two books. The guts of the equation are below. You wont actually type in the '[book2]SheetName' portion, this will need to reflect the name of your other workbook and the sheet that you are looking at within that book.
A2 = Look up value (in your example 6.02)
X1 = Column the return value is (in your example "dog")
X2 = Column Index Number (Of if you are not starting from A it represents the (Index Col of Value - Index of Look up Value) + 1
=VLOOKUP(A2,'[Book2]SheetName'!$A$X1,X2,0)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am new to VBA,I have a string I_HEAD_FOR
I wanted to extract the substring which is started and ended by special character '_'(Underscore) in VBA.
I need code snippet which can do above task,Could you please help me with it
Here in this case The code should extract substring HEAD
This the idea is from:
I_HEAD_FOR
to get as a result: HEAD
How about:
Public Function UnderScore(s As String) As String
UnderScore = Split(s, "_")(1)
End Function
If you want to use Excel, without VBA, this is the way you should think to make the formula:
On which position is the first _ sign?
Knowing the first position of the first sign, can I find the second _ sign?
Now, knowing the first and the second position, is there a way to extract only the string, which is between the two positions?
How can I unite the whole party into one formula, without getting crazy?
The Formulas SEARCH and MID together are pretty powerful. The SEARCH formula has optional value, saying where should you start search (see the second formula). Thus, we add +1 to the first found value. In the second formula, the -1 is added, because we do not want the position of the _, but the position before.
The formulas in text:
=SEARCH("_",A1,1)
=SEARCH("_",A1,SEARCH("_",A1,1)+1)-1
=MID(A1,B1+1,B2-B1)
=MID(A1,SEARCH("_",A1,1)+1,SEARCH("_",A1,SEARCH("_",A1,1)+1)-1-SEARCH("_",A1,1))
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 know the range name of the start of a list - 1 column wide and x rows deep.
How do I calculate x?
There is more data in the column than just this list. However, this list is contiguous - there is nothing in any of the cells above or below or either side beside it.
Sheet1.Range("myrange").Rows.Count
Function ListRowCount(ByVal FirstCellName as String) as Long
With thisworkbook.Names(FirstCellName).RefersToRange
If isempty(.Offset(1,0).value) Then
ListRowCount = 1
Else
ListRowCount = .End(xlDown).row - .row + 1
End If
End With
End Function
But if you are damn sure there's nothing around the list, then just thisworkbook.Names(FirstCellName).RefersToRange.CurrentRegion.rows.count
Why not use an Excel formula to determine the rows? For instance, if you are looking for how many cells contain data in Column A use this:
=COUNTIFS(A:A,"<>")
You can replace <> with any value to get how many rows have that value in it.
=COUNTIFS(A:A,"2008")
This can be used for finding filled cells in a row too.
You can also use:
Range( RangeName ).end(xlDown).row
to find the last row with data in it starting at your named range.
I am sure that you probably wanted the answer that #GSerg gave. There is also a worksheet function called rows that will give you the number of rows.
So, if you have a named data range called Data that has 7 rows, then =ROWS(Data) will show 7 in that cell.
That single last line worked perfectly #GSerg.
The other function was what I had been working on but I don't like having to resort to UDF's unless absolutely necessary.
I had been trying a combination of excel and vba and had got this to work - but its clunky compared with your answer.
strArea = Sheets("Oper St Report CC").Range("cc_rev").CurrentRegion.Address
cc_rev_rows = "=ROWS(" & strArea & ")"
Range("cc_rev_count").Formula = cc_rev_rows