Have been searching for a few hours now I'm stuck. Not really sure what I'm searching for but guessing some VBA.
What I want to do in excel is this:
Have a predefined list i.e. [a,a#,b,c,c#...g#]
Now when somebody enters value 'A' into cell A20 then A19 will be the next on the list 'A#', A18 will be 'B', A17 will be 'C' etc.
If the value C is entered into cell A20 then A19 would be 'C#' and so on...
Once the list reaches G# it shall repeat from A again. This would repeat until cell A2 is reached.
Even a point in the right direction would be great as I don't really know what to search for. Have tried 'arrays' 'loop' 'cycle' without much luck.
Thanks in advance
You would do better learning the basics of VBA than searching for odd terms. Search for "Excel VBA Tutorial". There are many to choose from so try a few then complete the one that matches your learning style. I prefer books. I visited a good library; reviewed their Excel VBA Primers and then the borrowed what I thought were the best to try at home. Finally I bought the best as a permenent reference book.
Your questions is very unclear but I think you need a For Each loop within a Do loop. You will find an introduction to loops near the start of any tutorial or primer. Try to develop this:
Sub demo()
Dim CellId As Variant
Dim LoopCount As Long
' #### Replace Tidy with the name of a worksheet in your workbook.
With Worksheets("Tidy")
Do While True
For Each CellId In Array("A20", "A19", "A18", "A17")
Debug.Print CellId & "=" & .Range(CellId).Value
If LoopCount >= 3 Then
Exit Do
End If
Next
LoopCount = LoopCount + 1
Loop
End With
End Sub
Related
I have created a rexexp function in Access 2010 and am attempting to write a query that parses a metal alloy composition string into individual elements and their respective percentages.
A couple examples of the alloy string are:
bi50 pb24.95 sn12.5 cd12.5 ag.05
and
sn96.5 ag3 cu.5
So far, I have successfully used regular expressions to get the first element (EL1), the first percent (%1), and the second element (EL2). But have not been able to get further. The query I have written so far is:
SELECT tJobTime.Alloy,
UCase(regexp([alloy],"[a-z]+",False)) AS EL1,
regexp([alloy],"\d+\.?\d+",False) AS [%1],
UCase(regexp([alloy],"\s[a-z]+",False)) AS EL2,
regexp([alloy],"[a-z]+\s\d",False) AS [%2]
'Have not gone further because not sure of the correct regexp pattern
FROM tJobTime;
I am very new to regular expressions and would appreciate any help.
I'm working with a big excel file that has a lot of information on businesses my company works with. I just imported another large excel file and their was a difference in format. The larger file we already have has the address, state and zip code in separate columns each spaced two apart like so:
I didn't make this spreadsheet or else I wouldn't have put the columns like that, but thats how the lady that works with it likes it.
The problem is that the sheet I imported has the city, state, and zip info all in the same cell like this:
Trollville, NY 12345
I have already over the states since 99% of the new ones were all the same state which a quick find and replace all worked. I'm now left with this
Trollville 12345
I want to move that zip code four columns to the right into the proper cell. I wrote a basic regex but don't know much about excel-vba since I haven't used it in years, but this is what I've come up with. I just don't know how to tell vba to print output the matches (which I made into an array) into the appropriate column. This is what I have so far:
Function findZipCode(zipCode)
Dim regEx As New VBScript_RegExp_55.RegExp
Dim matches, s
regEx.Pattern = "\s\d{5}\W"
regEx.Global = True
s = ""
If regEx.Test(zipCode) Then
Set matches = regEx.Execute(zipCode)
For Each Match In matches
s = s & Match.Value
Next
findZipCode = s
Else
findZipCode = ""
End If
End Function
What do I need to add? I'm open to alternative methods too if there is an easier way to do this.
Thanks in advance for the advice
Can you use the in-built Excel Worksheet Functions?
Place this in target column =RIGHT(A2,5) would capture the rightmost 5 characters of your string iff they are numeric. This will work if all of your values data values have a 5-digit zip codes at the end.
Alternatively, you could wrap it with a conditional such as IF(ISNUMBER(VALUE(RIGHT(A2,5))),RIGHT(A2,5),""), whcih would add a layer of validation to the process.
Also, did you know there is an option that may do this for you automatically if your data is comma (or space) delimited Data ribbon->Text to columns
When I'am going to join two columns in the Libreoffice Calc, it seems that I have to do this by programming in Python for as far as I know, there is no way to index a cell by variable, specifically, to use a variable to denote the row number or column number.
I wonder whether there is no way to do this?
Many thanks if you could save me from write another temporary python script >_<
I feel you may need the INDIRECT function.
You can try with
="Good Morning Mr, " &INDIRECT("D" & A9)
which will give you
"Good morning, Mr White"
where D9 contains string "White", and A9 contains digit 9
Hope will help
I've got a column (with many thousands of rows) which I'd like to delimit into multiple rows. I have some experience using regular expressions in Excel, and I have some experience using delimiters in excel, but this one is just a tad too hard..
Let me give you three example-lines:
- 23-12-05: For sale for 2000. 2010-09-09: Not found
- 25-11-09: For sale for 3400. Last date found: 2010-07-08
- 18-06-08: For sale for 5500. 21-07-09: Changed from 5500 to 4900. 16-09-09: Jumped from 4900 to 4700. 2010-02-04: Not found
Most other lines follow these structures. How can I create a new column based on just the first symbols before [COLON]; A second column based on the symbols between the first [COLON] and the first [DOT]. How can I continue to the last IF the text LAST DATE is not found? Finally: How can I use regex (or another way) to use the text 'NOT FOUND' to paste the last date into a new column?
Trust me, I have been at this for quite some time now (sigh). Any help is much appreciated!
you can actually use formulas for this.
Assuming the text is in A1,
B1: =LEFT(A1,FIND(":",A1)-1)
C1: =MID(A1,FIND(":",A1)+1,FIND(".",A1,FIND(":",A1))-FIND(":",A1))
D1: =MID(A1,FIND(".",A1,FIND(":",A1))+1,LEN(A1))
E1: =MID(A1,FIND("Not found",A1)-12,10)
(I'm assuming the date format does not change for the E1)
By the way, this also works for me, to get the last date in a cell:
=LOOKUP(9999999999999999,FIND("**-**-**",A1,ROW($1:$1024)))
Only problem here is: I haven't the slightest clue what exactly I am doing here.
For example, I'd like to use the same code to find the FIRST occurence of a date.
Can anyone explain this code to me? Why am I searching for a very high number? What is it in this code that makes that I find the last occurence? What does it mean that the 'starting number' is "row(1:1024)"?
Anybody knows?
I have only recently started picking up VBA in excel and I have been going through various tutorials online but I have encountered a bit of a problem when getting to if statements. Based on the knowledge i have gained online and from my VB knowledge i came up with the following code.
Private Sub CommandButton1_Click()
Dim mynum As Integer, checker As String
mynum = Range("A1:A10").value
If mynum > 0 Then
checker = "check"
Else
checker = "missing"
End If
Range("B1:B10").value = checker
End Sub
The idea is that if there is a number over 0 in column a, the adjacent cell in column b is checked, if however its 0 or lower the adjacent cell says missing (if that makes any sense) theres no real point to this as I am learning the basics at the moment :)
Now my problem...basically when i attempt to debug this, I get the Type Mismatch error and i cant really see why this is so. I know that it works when i set the range as one cell rather than multiple cells so my best guess is that it has something to do with that. I have looked into it but again im getting results that only back up that this should work. I must have misread it somewhere but help would be appreciated. :)
You cannot Assign/Check values of range like this for what you are trying to do. One way would be to loop through your range. For Example
Private Sub CommandButton1_Click()
Dim Rng As Range, aCell As Range
Set Rng = Range("A1:A10")
For Each aCell In Rng
If aCell.Value > 0 Then
aCell.Offset(, 1).Value = "check"
Else
aCell.Offset(, 1).Value = "missing"
End If
Next
End Sub
EDIT
BTW, you don't need VBA for this. If you are open for a Non VBA solution then simply put this formula in Cell B1 and copy it down
=IF(A1>1,"Check","Missing")