BlackieHamel
Board Regular
- Joined
- May 9, 2014
- Messages
- 93
I have a worksheet with long phrases in Column A, and in Column B, I have a 3-letter snippet from the string in A, thus:
STONESTHROW NES 196
REALIGNMENT LIG 35
QUALITYTIME LIT 87
QUALITATIVE LIT 87
In this case, I'm looking for the 3 letters beginning in the 3rd position. I use the MID() function to do this.
My question is about the number in Column C. This is a count of how many rows appear in the separate worksheet with that three-letter name (NES, LIG, LIT, etc.) The formula I use to get that (which I got from a helpful person here -- thanks, Mr.Excel wonderful people!) is
=COUNTA(INDIRECT("'"&B1&"'!A:A")).
It works great. But now I'm running into trouble automating this, as I'm trying to use a Loop function to generate each line:
I'm sure my problem has to do with trying to convert "'"&B1&"' to "'"&B&" plus the variable i -- but I can't figure out how to do it right. Can you help? Thanks.
Blackie
STONESTHROW NES 196
REALIGNMENT LIG 35
QUALITYTIME LIT 87
QUALITATIVE LIT 87
In this case, I'm looking for the 3 letters beginning in the 3rd position. I use the MID() function to do this.
My question is about the number in Column C. This is a count of how many rows appear in the separate worksheet with that three-letter name (NES, LIG, LIT, etc.) The formula I use to get that (which I got from a helpful person here -- thanks, Mr.Excel wonderful people!) is
=COUNTA(INDIRECT("'"&B1&"'!A:A")).
It works great. But now I'm running into trouble automating this, as I'm trying to use a Loop function to generate each line:
Code:
Open filenamelong For Input As #1
i = 1
Do While Not EOF(1)
Line Input #1, textline
' this line works
Worksheets(newtestsheet).Range("B" & CStr(i)) = "=MID(A" & CStr(i) & "," & midposition & ",3)"
' this line generates a Runtime error "1004"
Worksheets(newtestsheet).Range("C" & CStr(i)) = "=COUNTA(INDIRECT(" '"&B" & CStr(i) & "'!A:A"))"
i = i + 1
Loop
I'm sure my problem has to do with trying to convert "'"&B1&"' to "'"&B&" plus the variable i -- but I can't figure out how to do it right. Can you help? Thanks.
Blackie