I am trying to replicate the following formula in a VBA script. I have created a few variables to allow me to loop through the cells properly.
I have one variable varIteration which is simply a counter of how many loops I make. I need to loop 6 times.
I also have a varColon which uses the following code
This will count the number of occurrences of the ";" in the cell. If the iteration variable is greater than the colon variable, I am just going to put a null string in my cell.
Here is what I have in Excel and it is operating properly.
Here is what I put in VBA
Q1 is a variable for the first question.
The context here is I have a worksheet with a number of responses to questions. some of the columns only have one answer and some of the columns have multiple answers separated by ";". I need to go through the sheet and pull the first 5 columns every time and then the first answer to each of the questions. Once I have that I need to repeat for the second, third ... answers. If there are only two answers, when I get to the third answer for a question, I will put nothing in the variable to indicate there was no answer.
I have 700 rows and a maximum of 6 answers to any question.
Any assistance would be greatly appreciated.
I have one variable varIteration which is simply a counter of how many loops I make. I need to loop 6 times.
I also have a varColon which uses the following code
VBA Code:
varColon = (Len(Range("E" & currentrow)) - Len(Replace(Range("E" & currentrow), ";", "")))
This will count the number of occurrences of the ";" in the cell. If the iteration variable is greater than the colon variable, I am just going to put a null string in my cell.
Here is what I have in Excel and it is operating properly.
Excel Formula:
=MID(E2,(FIND(";",E2)+1),(FIND(CHAR(1),SUBSTITUTE(E2,";",CHAR(1),2)) - FIND(";",E2)-1))
Here is what I put in VBA
VBA Code:
Q1 = Mid(Range("E" & currentrow), WorksheetFunction.Find(char(1), Substitute("E" & currentrow, ";", char(1), varIteration)), WorksheetFunction.Find(";", Range("E" & currentrow)) - 1)
Q1 is a variable for the first question.
The context here is I have a worksheet with a number of responses to questions. some of the columns only have one answer and some of the columns have multiple answers separated by ";". I need to go through the sheet and pull the first 5 columns every time and then the first answer to each of the questions. Once I have that I need to repeat for the second, third ... answers. If there are only two answers, when I get to the third answer for a question, I will put nothing in the variable to indicate there was no answer.
I have 700 rows and a maximum of 6 answers to any question.
Any assistance would be greatly appreciated.