A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

For each this, then that and that



 
 
Thread Tools Display Modes
  #1  
Old May 15th, 2009, 08:11 PM posted to microsoft.public.excel.misc
wal50
external usenet poster
 
Posts: 85
Default For each this, then that and that

If I drop the "X" part, the below will shade the cells I want. I just can't
get the syntax for adding - ActiveCell.Offset(0, 1) = "X".

I have tried several versions of this with only undesired results.

Any help would be appreciated. Thank in advance
wal50

Sub MarkCells()
Dim Cell As Range
Dim MarkThis As String
MarkThis = Application.InputBox("Enter Value to Mark", Type:=2)
Set rng = Application.InputBox("Enter Range to check -
A1:A20", Type:=8)
rng.Select
For Each Cell In Selection
If Cell.Value = MarkThis Then
Cell.Interior.ColorIndex = 4 And
ActiveCell.Offset(0, 1) = "X"
Next Cell
End Sub
  #2  
Old May 15th, 2009, 08:28 PM posted to microsoft.public.excel.misc
Dave Peterson
external usenet poster
 
Posts: 19,791
Default For each this, then that and that

Maybe just changing:

ActiveCell.Offset(0, 1) = "X"
to
Cell.Offset(0, 1).Value = "X"

Since you're not activating/selecting the cell when you loop through them.

(I like specifying the property, too.)



wal50 wrote:

If I drop the "X" part, the below will shade the cells I want. I just can't
get the syntax for adding - ActiveCell.Offset(0, 1) = "X".

I have tried several versions of this with only undesired results.

Any help would be appreciated. Thank in advance
wal50

Sub MarkCells()
Dim Cell As Range
Dim MarkThis As String
MarkThis = Application.InputBox("Enter Value to Mark", Type:=2)
Set rng = Application.InputBox("Enter Range to check -
A1:A20", Type:=8)
rng.Select
For Each Cell In Selection
If Cell.Value = MarkThis Then
Cell.Interior.ColorIndex = 4 And
ActiveCell.Offset(0, 1) = "X"
Next Cell
End Sub


--

Dave Peterson
  #3  
Old May 15th, 2009, 08:29 PM posted to microsoft.public.excel.misc
Bernard Liengme[_2_]
external usenet poster
 
Posts: 1,027
Default For each this, then that and that

Try this - it worked for me

Sub MarkCells()
Dim Cell As Range
Dim MarkThis As String
MarkThis = Application.InputBox("Enter Value to Mark", Type:=2)
Set rng = Application.InputBox("Enter Range to check - A1: A20 ", Type:=8)
For Each Cell In rng
If Cell.Value = MarkThis Then
Cell.Interior.ColorIndex = 4
Cell.Offset(0, 1) = "X"
End If
Next Cell
End Sub

There is no need to do the Select; it did not change the active cell as you
went through the loop
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"wal50" wrote in message
...
If I drop the "X" part, the below will shade the cells I want. I just
can't
get the syntax for adding - ActiveCell.Offset(0, 1) = "X".

I have tried several versions of this with only undesired results.

Any help would be appreciated. Thank in advance
wal50

Sub MarkCells()
Dim Cell As Range
Dim MarkThis As String
MarkThis = Application.InputBox("Enter Value to Mark",
Type:=2)
Set rng = Application.InputBox("Enter Range to check -
A1:A20", Type:=8)
rng.Select
For Each Cell In Selection
If Cell.Value = MarkThis Then
Cell.Interior.ColorIndex = 4 And
ActiveCell.Offset(0, 1) = "X"
Next Cell
End Sub



  #4  
Old May 15th, 2009, 08:51 PM posted to microsoft.public.excel.misc
wal50
external usenet poster
 
Posts: 85
Default For each this, then that and that

Thank you gentlemen. This a valuable and educational resource.

"Bernard Liengme" wrote:

Try this - it worked for me

Sub MarkCells()
Dim Cell As Range
Dim MarkThis As String
MarkThis = Application.InputBox("Enter Value to Mark", Type:=2)
Set rng = Application.InputBox("Enter Range to check - A1: A20 ", Type:=8)
For Each Cell In rng
If Cell.Value = MarkThis Then
Cell.Interior.ColorIndex = 4
Cell.Offset(0, 1) = "X"
End If
Next Cell
End Sub

There is no need to do the Select; it did not change the active cell as you
went through the loop
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"wal50" wrote in message
...
If I drop the "X" part, the below will shade the cells I want. I just
can't
get the syntax for adding - ActiveCell.Offset(0, 1) = "X".

I have tried several versions of this with only undesired results.

Any help would be appreciated. Thank in advance
wal50

Sub MarkCells()
Dim Cell As Range
Dim MarkThis As String
MarkThis = Application.InputBox("Enter Value to Mark",
Type:=2)
Set rng = Application.InputBox("Enter Range to check -
A1:A20", Type:=8)
rng.Select
For Each Cell In Selection
If Cell.Value = MarkThis Then
Cell.Interior.ColorIndex = 4 And
ActiveCell.Offset(0, 1) = "X"
Next Cell
End Sub




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


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


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