D
davidm
I have tried to deploy the 2 MID concepts-Statement vs. Function t
effect replacements in a range-----and have gotten stuck in a spin.
Consider, lines of string like:
*** CODE1 Begins here ****
<some other lines>
*** CODE2 Begins here ****
<some other lines>
etc. etc. etc.
occupying Range("A1:A2150").
I need to convert to comments all lines beginning with asterick (*) an
have them read as follows:
Rem CODE1 Begins here ****
<some other lines>
Rem CODE2 Begins here ****
The code I stitched up (largely to test out the nuances of the MI
FUNCTION and MID STATEMENT) is:
Sub CommentOutWithRem()
Dim c as variant ' as Range or Object produces MisMatch errors
For each c in Range("a1:a2150")
If Mid(c,1,1)="*" Then Mid(c,1,3)="REM"
*'the sticky point follows in making an assignment:
'note, no action takes place if the code ends here.
*
c.value =c.value 'error: object required
c.Value = Mid(c, 1, 3) = "REM" 'error: object required
End if
next
End sub
Can someone kindly unknot the problem here? [I have very easily applie
other routine constructs to do what I want the code to do but there ar
obviously useful lessons to be learnt about theinteraction of the MI
function and its kin, the statement.
Many thanks in advance
effect replacements in a range-----and have gotten stuck in a spin.
Consider, lines of string like:
*** CODE1 Begins here ****
<some other lines>
*** CODE2 Begins here ****
<some other lines>
etc. etc. etc.
occupying Range("A1:A2150").
I need to convert to comments all lines beginning with asterick (*) an
have them read as follows:
Rem CODE1 Begins here ****
<some other lines>
Rem CODE2 Begins here ****
The code I stitched up (largely to test out the nuances of the MI
FUNCTION and MID STATEMENT) is:
Sub CommentOutWithRem()
Dim c as variant ' as Range or Object produces MisMatch errors
For each c in Range("a1:a2150")
If Mid(c,1,1)="*" Then Mid(c,1,3)="REM"
*'the sticky point follows in making an assignment:
'note, no action takes place if the code ends here.
*
c.value =c.value 'error: object required
c.Value = Mid(c, 1, 3) = "REM" 'error: object required
End if
next
End sub
Can someone kindly unknot the problem here? [I have very easily applie
other routine constructs to do what I want the code to do but there ar
obviously useful lessons to be learnt about theinteraction of the MI
function and its kin, the statement.
Many thanks in advance