B
Bob Reynolds
I have a very specific spreadsheet that I acquired some vb off of the
newsgroups. Unfortunately I have one formula in vb that is quite lengthy and
I can't get it to work on the workbook that I have. I've tried everything
that I know (not much) and could use some help. If someone needs it to look
at it can be provided.
I've attached the vb code so you can see what I'm talking about b4 looking
at mine.
Basically it goes to the "Examples" sheet and looks in the defined range
letters. There can be 31 entries there and it looks up and down and gives
the starting letter and the ending letter. Once it does this it's supposed
to put those two letters into the concatenate formula with a result of A
through to AA, or something like that. When I run it it returns nothing but
the "through to".....Any help would be appreciated..
Bob
Sub findfirstandlast()
Dim rng As Range
Dim myarray(2) As String
Dim settext As String
settext = """ through to """
Set rng = Sheets("EXAMPLES").Range("rng_Letters")
For Each cell In rng
If cell = "A" Then
myarray(1) = "A"
Exit For
ElseIf cell = "B" Then
myarray(1) = "B"
Exit For
ElseIf cell = "C" Then
myarray(1) = "C"
Exit For
ElseIf cell = "D" Then
myarray(1) = "D"
Exit For
ElseIf cell = "E" Then
myarray(1) = "E"
Exit For
ElseIf cell = "F" Then
myarray(1) = "F"
Exit For
ElseIf cell = "G" Then
myarray(1) = "G"
Exit For
ElseIf cell = "H" Then
myarray(1) = "H"
Exit For
ElseIf cell = "I" Then
myarray(1) = "I"
Exit For
ElseIf cell = "J" Then
myarray(1) = "J"
Exit For
ElseIf cell = "K" Then
myarray(1) = "K"
Exit For
ElseIf cell = "L" Then
myarray(1) = "L"
Exit For
ElseIf cell = "M" Then
myarray(1) = "M"
Exit For
ElseIf cell = "N" Then
myarray(1) = "N"
Exit For
ElseIf cell = "O" Then
myarray(1) = "O"
Exit For
ElseIf cell = "P" Then
myarray(1) = "P"
Exit For
ElseIf cell = "Q" Then
myarray(1) = "Q"
Exit For
ElseIf cell = "R" Then
myarray(1) = "R"
Exit For
ElseIf cell = "S" Then
myarray(1) = "S"
Exit For
ElseIf cell = "T" Then
myarray(1) = "T"
Exit For
ElseIf cell = "U" Then
myarray(1) = "U"
Exit For
ElseIf cell = "V" Then
myarray(1) = "V"
Exit For
ElseIf cell = "W" Then
myarray(1) = "W"
Exit For
ElseIf cell = "X" Then
myarray(1) = "X"
Exit For
ElseIf cell = "Y" Then
myarray(1) = "Y"
Exit For
ElseIf cell = "Z" Then
myarray(1) = "Z"
Exit For
ElseIf cell = "AA" Then
myarray(1) = "AA"
Exit For
ElseIf cell = "AB" Then
myarray(1) = "AB"
Exit For
ElseIf cell = "AC" Then
myarray(1) = "AC"
Exit For
ElseIf cell = "AD" Then
myarray(1) = "AD"
Exit For
ElseIf cell = "AE" Then
myarray(1) = "AE"
Exit For
ElseIf cell = "AF" Then
myarray(1) = "AF"
Exit For
End If
Next
For Each cell In rng
If cell = "AF" Then
myarray(2) = "AF"
ElseIf cell = "AE" Then
myarray(2) = "AE"
ElseIf cell = "AD" Then
myarray(2) = "AD"
ElseIf cell = "AC" Then
myarray(2) = "AC"
ElseIf cell = "AB" Then
myarray(2) = "AB"
ElseIf cell = "AA" Then
myarray(2) = "AA"
ElseIf cell = "Z" Then
myarray(2) = "Z"
ElseIf cell = "Y" Then
myarray(2) = "Y"
ElseIf cell = "X" Then
myarray(2) = "X"
ElseIf cell = "W" Then
myarray(2) = "W"
ElseIf cell = "V" Then
myarray(2) = "V"
ElseIf cell = "U" Then
myarray(2) = "U"
ElseIf cell = "T" Then
myarray(2) = "T"
ElseIf cell = "S" Then
myarray(2) = "S"
ElseIf cell = "R" Then
myarray(2) = "R"
ElseIf cell = "Q" Then
myarray(2) = "Q"
ElseIf cell = "P" Then
myarray(2) = "P"
ElseIf cell = "O" Then
myarray(2) = "O"
ElseIf cell = "N" Then
myarray(2) = "N"
ElseIf cell = "M" Then
myarray(2) = "M"
ElseIf cell = "L" Then
myarray(2) = "L"
ElseIf cell = "K" Then
myarray(2) = "K"
ElseIf cell = "J" Then
myarray(2) = "J"
ElseIf cell = "I" Then
myarray(2) = "I"
ElseIf cell = "H" Then
myarray(2) = "H"
ElseIf cell = "G" Then
myarray(2) = "G"
ElseIf cell = "F" Then
myarray(2) = "F"
ElseIf cell = "E" Then
myarray(2) = "E"
ElseIf cell = "D" Then
myarray(2) = "D"
ElseIf cell = "C" Then
myarray(2) = "C"
ElseIf cell = "B" Then
myarray(2) = "B"
ElseIf cell = "A" Then
myarray(2) = "A"
End If
Next
Sheets("Data Entry_").Select
Range("K33").FormulaR1C1 = "=Concatenate(""" & myarray(1) & """," &
settext & " ,""" & myarray(2) & """)"
End Sub
newsgroups. Unfortunately I have one formula in vb that is quite lengthy and
I can't get it to work on the workbook that I have. I've tried everything
that I know (not much) and could use some help. If someone needs it to look
at it can be provided.
I've attached the vb code so you can see what I'm talking about b4 looking
at mine.
Basically it goes to the "Examples" sheet and looks in the defined range
letters. There can be 31 entries there and it looks up and down and gives
the starting letter and the ending letter. Once it does this it's supposed
to put those two letters into the concatenate formula with a result of A
through to AA, or something like that. When I run it it returns nothing but
the "through to".....Any help would be appreciated..
Bob
Sub findfirstandlast()
Dim rng As Range
Dim myarray(2) As String
Dim settext As String
settext = """ through to """
Set rng = Sheets("EXAMPLES").Range("rng_Letters")
For Each cell In rng
If cell = "A" Then
myarray(1) = "A"
Exit For
ElseIf cell = "B" Then
myarray(1) = "B"
Exit For
ElseIf cell = "C" Then
myarray(1) = "C"
Exit For
ElseIf cell = "D" Then
myarray(1) = "D"
Exit For
ElseIf cell = "E" Then
myarray(1) = "E"
Exit For
ElseIf cell = "F" Then
myarray(1) = "F"
Exit For
ElseIf cell = "G" Then
myarray(1) = "G"
Exit For
ElseIf cell = "H" Then
myarray(1) = "H"
Exit For
ElseIf cell = "I" Then
myarray(1) = "I"
Exit For
ElseIf cell = "J" Then
myarray(1) = "J"
Exit For
ElseIf cell = "K" Then
myarray(1) = "K"
Exit For
ElseIf cell = "L" Then
myarray(1) = "L"
Exit For
ElseIf cell = "M" Then
myarray(1) = "M"
Exit For
ElseIf cell = "N" Then
myarray(1) = "N"
Exit For
ElseIf cell = "O" Then
myarray(1) = "O"
Exit For
ElseIf cell = "P" Then
myarray(1) = "P"
Exit For
ElseIf cell = "Q" Then
myarray(1) = "Q"
Exit For
ElseIf cell = "R" Then
myarray(1) = "R"
Exit For
ElseIf cell = "S" Then
myarray(1) = "S"
Exit For
ElseIf cell = "T" Then
myarray(1) = "T"
Exit For
ElseIf cell = "U" Then
myarray(1) = "U"
Exit For
ElseIf cell = "V" Then
myarray(1) = "V"
Exit For
ElseIf cell = "W" Then
myarray(1) = "W"
Exit For
ElseIf cell = "X" Then
myarray(1) = "X"
Exit For
ElseIf cell = "Y" Then
myarray(1) = "Y"
Exit For
ElseIf cell = "Z" Then
myarray(1) = "Z"
Exit For
ElseIf cell = "AA" Then
myarray(1) = "AA"
Exit For
ElseIf cell = "AB" Then
myarray(1) = "AB"
Exit For
ElseIf cell = "AC" Then
myarray(1) = "AC"
Exit For
ElseIf cell = "AD" Then
myarray(1) = "AD"
Exit For
ElseIf cell = "AE" Then
myarray(1) = "AE"
Exit For
ElseIf cell = "AF" Then
myarray(1) = "AF"
Exit For
End If
Next
For Each cell In rng
If cell = "AF" Then
myarray(2) = "AF"
ElseIf cell = "AE" Then
myarray(2) = "AE"
ElseIf cell = "AD" Then
myarray(2) = "AD"
ElseIf cell = "AC" Then
myarray(2) = "AC"
ElseIf cell = "AB" Then
myarray(2) = "AB"
ElseIf cell = "AA" Then
myarray(2) = "AA"
ElseIf cell = "Z" Then
myarray(2) = "Z"
ElseIf cell = "Y" Then
myarray(2) = "Y"
ElseIf cell = "X" Then
myarray(2) = "X"
ElseIf cell = "W" Then
myarray(2) = "W"
ElseIf cell = "V" Then
myarray(2) = "V"
ElseIf cell = "U" Then
myarray(2) = "U"
ElseIf cell = "T" Then
myarray(2) = "T"
ElseIf cell = "S" Then
myarray(2) = "S"
ElseIf cell = "R" Then
myarray(2) = "R"
ElseIf cell = "Q" Then
myarray(2) = "Q"
ElseIf cell = "P" Then
myarray(2) = "P"
ElseIf cell = "O" Then
myarray(2) = "O"
ElseIf cell = "N" Then
myarray(2) = "N"
ElseIf cell = "M" Then
myarray(2) = "M"
ElseIf cell = "L" Then
myarray(2) = "L"
ElseIf cell = "K" Then
myarray(2) = "K"
ElseIf cell = "J" Then
myarray(2) = "J"
ElseIf cell = "I" Then
myarray(2) = "I"
ElseIf cell = "H" Then
myarray(2) = "H"
ElseIf cell = "G" Then
myarray(2) = "G"
ElseIf cell = "F" Then
myarray(2) = "F"
ElseIf cell = "E" Then
myarray(2) = "E"
ElseIf cell = "D" Then
myarray(2) = "D"
ElseIf cell = "C" Then
myarray(2) = "C"
ElseIf cell = "B" Then
myarray(2) = "B"
ElseIf cell = "A" Then
myarray(2) = "A"
End If
Next
Sheets("Data Entry_").Select
Range("K33").FormulaR1C1 = "=Concatenate(""" & myarray(1) & """," &
settext & " ,""" & myarray(2) & """)"
End Sub