Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default A Little More Advanced Range Fill-In

I have this function:

myKey = Key()
Selection.Value = myKey

If the user highlights a range, a specific value is filled into every single
cell highlighted. I want to do this a little better. If the user
highlights several rows and columns, I want the myKey to only fill in if the
column header (Row 1 value) is "Key" - is this possible in VBA?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default A Little More Advanced Range Fill-In

Sub test()

myKey = Key()
For Each cell In ActiveSheet.Selection
If Cells(1, cell.Column) = "Key" Then
cell.Value = myKey
End If
Next cell

End Sub


"Derek Hart" wrote:

I have this function:

myKey = Key()
Selection.Value = myKey

If the user highlights a range, a specific value is filled into every single
cell highlighted. I want to do this a little better. If the user
highlights several rows and columns, I want the myKey to only fill in if the
column header (Row 1 value) is "Key" - is this possible in VBA?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default A Little More Advanced Range Fill-In

I get the error:

"Compile Error: For Each control variable must be Variant or Object"

How would I correct this code?

Derek


"Joel" wrote in message
...
Sub test()

myKey = Key()
For Each cell In ActiveSheet.Selection
If Cells(1, cell.Column) = "Key" Then
cell.Value = myKey
End If
Next cell

End Sub


"Derek Hart" wrote:

I have this function:

myKey = Key()
Selection.Value = myKey

If the user highlights a range, a specific value is filled into every
single
cell highlighted. I want to do this a little better. If the user
highlights several rows and columns, I want the myKey to only fill in if
the
column header (Row 1 value) is "Key" - is this possible in VBA?





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default A Little More Advanced Range Fill-In

did you have the error before my changes? I don't get the error with Excel
2003. Can you post your entire code?

"Derek Hart" wrote:

I get the error:

"Compile Error: For Each control variable must be Variant or Object"

How would I correct this code?

Derek


"Joel" wrote in message
...
Sub test()

myKey = Key()
For Each cell In ActiveSheet.Selection
If Cells(1, cell.Column) = "Key" Then
cell.Value = myKey
End If
Next cell

End Sub


"Derek Hart" wrote:

I have this function:

myKey = Key()
Selection.Value = myKey

If the user highlights a range, a specific value is filled into every
single
cell highlighted. I want to do this a little better. If the user
highlights several rows and columns, I want the myKey to only fill in if
the
column header (Row 1 value) is "Key" - is this possible in VBA?






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default A Little More Advanced Range Fill-In

Dim myKey As String
myKey = Key()
For Each objCell In ActiveSheet.Selection
If Cells(1, objCell.Column) = "Key" Then
objCell.Value = myKey
End If
Next objCell

What do you think?

"Joel" wrote in message
...
did you have the error before my changes? I don't get the error with
Excel
2003. Can you post your entire code?

"Derek Hart" wrote:

I get the error:

"Compile Error: For Each control variable must be Variant or Object"

How would I correct this code?

Derek


"Joel" wrote in message
...
Sub test()

myKey = Key()
For Each cell In ActiveSheet.Selection
If Cells(1, cell.Column) = "Key" Then
cell.Value = myKey
End If
Next cell

End Sub


"Derek Hart" wrote:

I have this function:

myKey = Key()
Selection.Value = myKey

If the user highlights a range, a specific value is filled into every
single
cell highlighted. I want to do this a little better. If the user
highlights several rows and columns, I want the myKey to only fill in
if
the
column header (Row 1 value) is "Key" - is this possible in VBA?










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default A Little More Advanced Range Fill-In

chaging the variable cell to objcell doesn't solve your problem. there is
something else wrong. I need to see the entire code.

"Derek Hart" wrote:

Dim myKey As String
myKey = Key()
For Each objCell In ActiveSheet.Selection
If Cells(1, objCell.Column) = "Key" Then
objCell.Value = myKey
End If
Next objCell

What do you think?

"Joel" wrote in message
...
did you have the error before my changes? I don't get the error with
Excel
2003. Can you post your entire code?

"Derek Hart" wrote:

I get the error:

"Compile Error: For Each control variable must be Variant or Object"

How would I correct this code?

Derek


"Joel" wrote in message
...
Sub test()

myKey = Key()
For Each cell In ActiveSheet.Selection
If Cells(1, cell.Column) = "Key" Then
cell.Value = myKey
End If
Next cell

End Sub


"Derek Hart" wrote:

I have this function:

myKey = Key()
Selection.Value = myKey

If the user highlights a range, a specific value is filled into every
single
cell highlighted. I want to do this a little better. If the user
highlights several rows and columns, I want the myKey to only fill in
if
the
column header (Row 1 value) is "Key" - is this possible in VBA?









  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default A Little More Advanced Range Fill-In

I switched ActiveSheet.Selection to just Selection and it solved it. Not
sure why the ActiveSheet reference does not work for me, but it works. Do
you know why I cannot reference ActiveSheet?


"Joel" wrote in message
...
chaging the variable cell to objcell doesn't solve your problem. there is
something else wrong. I need to see the entire code.

"Derek Hart" wrote:

Dim myKey As String
myKey = Key()
For Each objCell In ActiveSheet.Selection
If Cells(1, objCell.Column) = "Key" Then
objCell.Value = myKey
End If
Next objCell

What do you think?

"Joel" wrote in message
...
did you have the error before my changes? I don't get the error with
Excel
2003. Can you post your entire code?

"Derek Hart" wrote:

I get the error:

"Compile Error: For Each control variable must be Variant or Object"

How would I correct this code?

Derek


"Joel" wrote in message
...
Sub test()

myKey = Key()
For Each cell In ActiveSheet.Selection
If Cells(1, cell.Column) = "Key" Then
cell.Value = myKey
End If
Next cell

End Sub


"Derek Hart" wrote:

I have this function:

myKey = Key()
Selection.Value = myKey

If the user highlights a range, a specific value is filled into
every
single
cell highlighted. I want to do this a little better. If the user
highlights several rows and columns, I want the myKey to only fill
in
if
the
column header (Row 1 value) is "Key" - is this possible in VBA?











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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Advanced excel fill handle Question Pete G[_2_] Excel Discussion (Misc queries) 2 January 13th 09 12:57 PM
Excel fill handle use -advanced Pete G[_2_] Excel Discussion (Misc queries) 1 January 13th 09 12:10 PM
advanced filter a range Il Principe Excel Worksheet Functions 2 August 1st 05 03:27 PM
Advanced Filter Range Selection in VB Hulk[_2_] Excel Programming 0 October 3rd 04 02:39 AM
how to? set my range= my UDF argument (range vs. value in range) [advanced?] Keith R[_3_] Excel Programming 2 August 11th 03 05:55 PM


All times are GMT +1. The time now is 04:56 PM.

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"