#1   Report Post  
Posted to microsoft.public.excel.misc
stats
 
Posts: n/a
Default macro

using macro, how can i assign list box (having values "yes" or "no" )
to all the fields of column D

  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave O
 
Posts: n/a
Default macro

Assuming you mean "cells" in your post, where you say "fields".

Do you *need* to perform this via macro? It's certainly very easy to
perform the operation once manually, and copy paste it into other
fields.

If you need to perform this via macro, you could record the manual
operation described above.

  #3   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default macro

How about selecting your range and then data|validation.

stats wrote:

using macro, how can i assign list box (having values "yes" or "no" )
to all the fields of column D


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
stats
 
Posts: n/a
Default macro

This is what i am looking

i want to create a macro, as soon as i open the spreadsheet, it should
run the macro automatically (which i guess can be done using Auto_Open)

the macro should behave as follows
1) if value in column A is of the format 2.2 (integer.integer), then
fill the column C of the same row with list box (containing "yes" or
"no")

2) if value in column A is of the format 2.2 (integer.integer), and
value of column C is "some string" then fill the column C with same
value (preserve the data if it already exists)

I guess i can't do this manually if i have more than 1000 rows.

  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default macro

If you select the whole range, you can do it all at once.



stats wrote:

This is what i am looking

i want to create a macro, as soon as i open the spreadsheet, it should
run the macro automatically (which i guess can be done using Auto_Open)

the macro should behave as follows
1) if value in column A is of the format 2.2 (integer.integer), then
fill the column C of the same row with list box (containing "yes" or
"no")

2) if value in column A is of the format 2.2 (integer.integer), and
value of column C is "some string" then fill the column C with same
value (preserve the data if it already exists)

I guess i can't do this manually if i have more than 1000 rows.


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.misc
stats
 
Posts: n/a
Default macro

Yeah, but I would liek to create a macro, as you see I have couple of
conditions to be satisfied before assigning..

is this doable using macro???

  #7   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default macro

This might help.

Option Explicit
Sub auto_open()

Dim myRng As Range
Dim myCell As Range

Set myRng = Worksheets("sheet1").Range("a1:A1000")

For Each myCell In myRng.Cells
With myCell
.Offset(0, 2).Validation.Delete
If IsNumeric(.Value) _
And .Text Like "#.#" Then
With .Offset(0, 2)
.Value = ""
With .Validation
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="Yes,No"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End With
End If
End With
Next myCell
End Sub



stats wrote:

Yeah, but I would liek to create a macro, as you see I have couple of
conditions to be satisfied before assigning..

is this doable using macro???


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.misc
stats
 
Posts: n/a
Default macro

Hey Dave, can u please explain the code in brief..i m new to VBA...

  #9   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default macro

Intermingled.


Option Explicit
Sub auto_open()

'define some variables
Dim myRng As Range
Dim myCell As Range

'what cells to look at. Change the worksheet name
'and the address to what you need
Set myRng = Worksheets("sheet1").Range("a1:A1000")

'look at each cell in that range
For Each myCell In myRng.Cells
With myCell
'offset(0,2) is two columns to the right
'since mycell is in column A, then .offset(0,2) is in column C
'remove any existing validation
.Offset(0, 2).Validation.Delete
If IsNumeric(.Value) _
And .Text Like "#.#" Then
'if it's a number that looks like 2.2 (or 3.6 or 7.9 or 8.0)
With .Offset(0, 2)
'clear out the value in Column C
.Value = ""
With .Validation
'add the Yes/No validation
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="Yes,No"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End With
else
'do nothing
'just leave column C's value alone.
End If
End With
Next myCell
End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

stats wrote:

Hey Dave, can u please explain the code in brief..i m new to VBA...


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.misc
stats
 
Posts: n/a
Default macro

Hey david,

it is not preserving the value of column C. If the valus already exists
it should preserver the data instead of creating list box



  #11   Report Post  
Posted to microsoft.public.excel.misc
stats
 
Posts: n/a
Default macro

Hey David,

you are clearing the column C and adding the validation

i want to add validation only if column C is empty

  #12   Report Post  
Posted to microsoft.public.excel.misc
stats
 
Posts: n/a
Default macro

i think so, this will work out

For Each myCell In myRng.Cells
With myCell
.Offset(0, 2).Validation.Delete
If IsNumeric(.Value) _
And .Text Like "#.#" Then
With .Offset(0, 2)
If IsEmpty(.Value) Then
.Value = ""
With .Validation
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="Yes,No"

End With
End If
End With
End If
End With
Next myCell

Next

  #13   Report Post  
Posted to microsoft.public.excel.misc
stats
 
Posts: n/a
Default macro

Hey David,

is it possible to set the color, I mean if user selects yes the color
of cell should change to red
if no is selectd then blac etc

  #14   Report Post  
Posted to microsoft.public.excel.misc
stats
 
Posts: n/a
Default macro

Hey david, i guess i can do this to change color

If IsEmpty(.Value) Then
.Value = ""
.Interior.ColorIndex = 34


But there is one issue with macro, once i select the cell, select yes
and when i again click on the same cell, i do not get the drop down
box...the value gets fixed to yes...this should not happen

  #15   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default macro

There's nothing in that code that removes the data|validation after it's
applied.

stats wrote:

Hey david, i guess i can do this to change color

If IsEmpty(.Value) Then
.Value = ""
.Interior.ColorIndex = 34

But there is one issue with macro, once i select the cell, select yes
and when i again click on the same cell, i do not get the drop down
box...the value gets fixed to yes...this should not happen


--

Dave Peterson


  #16   Report Post  
Posted to microsoft.public.excel.misc
stats
 
Posts: n/a
Default macro

hey david, this works fine for integer of type 2.2
And .Text Like "#.#" Then
'if it's a number that looks like 2.2 (or 3.6 or 7.9 or
8.0)

what to do for 2.2.2.2
i tried #.#.#.# it didn't worekd

  #17   Report Post  
Posted to microsoft.public.excel.misc
stats
 
Posts: n/a
Default macro

Please ignore my previous question...

the only thing is how can i change the cell color based on selection
from list box

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
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
macro with F9 Kenny Excel Discussion (Misc queries) 1 August 3rd 05 02:41 PM
Make Alignment options under format cells available as shortcut dforrest Excel Discussion (Misc queries) 1 July 14th 05 10:58 PM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM


All times are GMT +1. The time now is 03:06 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"