#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 187
Default For Each in VBA

I have the following macro which isn't working:

Sub EachTest()
Dim A As Variant, MyString As String
MyString = "10"
For Each A In Range("A10:A20")
If A.Value = True Then MyString
Next
End Sub

When this is run I get an error: "Compile error. Expected Sub,
Function or Property."

I'm trying to replace TRUE values in A10:A20 with the number 10 and
ignore the FALSE values.

Presumably I'm missing something simple here.

Thanks,

Dave

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default For Each in VBA

Sub EachTest()
Dim A As Range, MyString As String
MyString = "10"
For Each A In Range("A10:A20")
If A.Value = True Then A.value = MyString
Next
End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Dave F" wrote in message
oups.com...
I have the following macro which isn't working:

Sub EachTest()
Dim A As Variant, MyString As String
MyString = "10"
For Each A In Range("A10:A20")
If A.Value = True Then MyString
Next
End Sub

When this is run I get an error: "Compile error. Expected Sub,
Function or Property."

I'm trying to replace TRUE values in A10:A20 with the number 10 and
ignore the FALSE values.

Presumably I'm missing something simple here.

Thanks,

Dave



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default For Each in VBA

Sub EachTest()
Dim A As Variant, MyString As String
MyString = "10"
For Each A In Range("A10:A20")
If A.Value = True Then
A.Value = MyString
End If
Next
End Sub


--
Gary''s Student - gsnu200736


"Dave F" wrote:

I have the following macro which isn't working:

Sub EachTest()
Dim A As Variant, MyString As String
MyString = "10"
For Each A In Range("A10:A20")
If A.Value = True Then MyString
Next
End Sub

When this is run I get an error: "Compile error. Expected Sub,
Function or Property."

I'm trying to replace TRUE values in A10:A20 with the number 10 and
ignore the FALSE values.

Presumably I'm missing something simple here.

Thanks,

Dave


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 187
Default For Each in VBA

Thanks, works perfectly

On Aug 9, 11:42 am, Gary''s Student
wrote:
Sub EachTest()
Dim A As Variant, MyString As String
MyString = "10"
For Each A In Range("A10:A20")
If A.Value = True Then
A.Value = MyString
End If
Next
End Sub

--
Gary''s Student - gsnu200736



"Dave F" wrote:
I have the following macro which isn't working:


Sub EachTest()
Dim A As Variant, MyString As String
MyString = "10"
For Each A In Range("A10:A20")
If A.Value = True Then MyString
Next
End Sub


When this is run I get an error: "Compile error. Expected Sub,
Function or Property."


I'm trying to replace TRUE values in A10:A20 with the number 10 and
ignore the FALSE values.


Presumably I'm missing something simple here.


Thanks,


Dave- Hide quoted text -


- Show quoted text -



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"