Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Cell data depending on column selected.

A pretty simple VBA problem in excel

I am trying to create a simple module to input either P1 or P2 in
selected cells.

If the column selected is D, E, F G

D and E should equal P1
F and G should equal P2

This should work for any combination such as if only D or G is selected
D = P1, G = P2.

I have the following worked out but I cannot get it to fill in the
cells properly, if I only select a single cell it works fine, but if I
select D - G it fills it all with P1.

code:
Sub CellFill()

If (ActiveCell.Column = 4 Or ActiveCell.Column = 5) Then
ActiveCell.Value = "P1"
Else
ActiveCell.Value = "P2"
End If

End Sub
/code



Any help is appreciated

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Cell data depending on column selected.

Sub CellFill()
Dim cell As Range

For Each cell In Selection
If (cell.Column = 4 Or cell.Column = 5) Then
cell.Value = "P1"
Else
cell.Value = "P2"
End If
Next cell

End Sub



--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

wrote in message
oups.com...
A pretty simple VBA problem in excel

I am trying to create a simple module to input either P1 or P2 in
selected cells.

If the column selected is D, E, F G

D and E should equal P1
F and G should equal P2

This should work for any combination such as if only D or G is selected
D = P1, G = P2.

I have the following worked out but I cannot get it to fill in the
cells properly, if I only select a single cell it works fine, but if I
select D - G it fills it all with P1.

code:
Sub CellFill()

If (ActiveCell.Column = 4 Or ActiveCell.Column = 5) Then
ActiveCell.Value = "P1"
Else
ActiveCell.Value = "P2"
End If

End Sub
/code



Any help is appreciated



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
Can I show a picture depending on what data is selected in a cell Lesley Murray Excel Discussion (Misc queries) 3 April 12th 07 04:34 PM
splitting one column into rows depending on the data in the column [email protected] Excel Programming 1 March 11th 06 11:48 AM
Want add color to the cell depending on the value selected from th Tom Ogilvy Excel Programming 0 August 16th 05 07:11 PM
return a data list depending on a value selected within a drop dow loren Excel Discussion (Misc queries) 1 April 11th 05 05:17 PM
Populating dropdown list 2 with data depending upon what was selected in list 1 karambos Excel Programming 2 November 9th 04 05:32 PM


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