I am trying to create a do loop that will go to the range of my sheet ("A") and retrieve the value and put it to i variable. I want to run this loop until I hit an empty row. Right now I am using Is ""
, if I use Do Until unique_numbers.Range("A" & i) = Empty
I get this error (). I am copying over a VBA script to vb for efficiency purposes (very new to this).
Dim xlNewSheet = DirectCast(worksheets.Add(worksheets(1), Type.Missing, Type.Missing, Type.Missing), Excel.Worksheet)
xlNewSheet.Name = "Unique Numbers"
Dim unique_numbers As Object
unique_numbers = xlWorkBook.Sheets("Unique Numbers")
Dim i As Integer
i = 2 'Starting from two since the first row is the header
Do Until unique_numbers.Range("A" & i) Is ""
unique_numbers.Range("A" & i) = convert_to_acronym(unique_numbers.Range("A" & i))
Loop
The sub function I am trying to call in order to manipulate data in column A:
Private Sub convert_to_acronym(hex_value As String)
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim convert_to_acronym
Dim sym As Object
sym = xlWorkBook.Sheets("sym")
Dim k As Integer : k = 0
Dim found As Integer : found = 0
Dim tmp As String
Dim current_string As String
Dim name_start As Integer
'If the trace has 0, then convert it to "0000" which is a better format for parsing the data
If hex_value = "0" Then
hex_value = "0000"
End If
'If the first character of the string is < "F", then the message is point.
'reconstruct the string by taking the first two characters and adding "FE" before comparing it with sym.
If LBound(hex_value.ToArray, 1) < "F" Then
hex_value = LBound(hex_value.ToArray, 2) & "FE"
End If
Do While found = 0
k = k + 1
current_string = InStr(sym.Range("A"), k)
name_start = InStr(current_string, hex_value)
If name_start = 6 Then
found = 1
End If
If k = 32766 Then
'To do: current_string was not found
found = 1
End If
Loop
tmp = sym.Range("A" & k - 1)
tmp = Replace(tmp, "[", "")
tmp = Replace(tmp, "]", "")
convert_to_acronym = tmp
End Sub
When my application crashes it actually highlights the second line with the title of this question. I assume the Do Until line is causing this, I could be wrong.(convert_to_acronym) references a Module I have created that contains logic to convert HEX value to an Acronym.