Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default activate macro by values in a column


Hi Brian,
I'm based in the 'Naki at the moment & have been enjoying the long
weekend :-)
Hopefully the macro below does everything you want (I'm sure there are
ways of tidying it up but it should work as is - provided the line
breaks are all in the right place when you copy it).
fyi, I adapted the principles of using multiple ranges from
"CopyMultipleSelection", a macro written by John Walkenbach - an Excel
guru - which I downloaded in a file called "copymult.xls".

The macro below relies on the headers being in row 2 & the first row of
data being row 3.
btw, the "abs" means that it selects any of the cells that have an
absolute value of 2 ie it could = "-2" or "2". If this is what you want
to happen, change the first line of code from:
Range("a2:r" & Application.CountA(Range("r2:R" &
(Rows.Count)))).AutoFilter Field:=18, Criteria1:="2"
to
Range("a2:r" & Application.CountA(Range("r2:R" &
(Rows.Count)))).AutoFilter Field:=18, Criteria1:="=2", Operator:=xlOr,
_
Criteria2:="=-2"



Code:
--------------------
Sub ModifiedItemsToPrice()
application.screenupdating = false
'To filter for rows with "2" in col R, select the area in col C to M for each of these rows 7 remove the autofilter
Range("a2:r" & Application.CountA(Range("r2:R" & (Rows.Count)))).AutoFilter Field:=18, Criteria1:="2"
On Error GoTo NoTwosFound
Range("c3:m" & Application.CountA(Range("r2:R" & (Rows.Count)))).SpecialCells(xlCellTypeVisible).Se lect
On Error GoTo 0
Selection.AutoFilter
'*
Dim SelAreas() As Range
Dim NumAreas As Integer, i As Integer
' Store the areas as separate Range objects
NumAreas = Selection.Areas.Count
ReDim SelAreas(1 To NumAreas)
For i = 1 To NumAreas
Set SelAreas(i) = Selection.Areas(i)
Next
' Copy and paste each area (col C to M) as values, same for col R, and clear contents of col H.
For i = 1 To NumAreas
SelAreas(i).Copy
SelAreas(i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("r" & SelAreas(i).Row & ":r" & SelAreas(i).Row + (SelAreas(i).Rows.Count - 1)).Copy
Range("r" & SelAreas(i).Row & ":r" & SelAreas(i).Row + (SelAreas(i).Rows.Count - 1)).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("h" & SelAreas(i).Row & ":h" & SelAreas(i).Row + (SelAreas(i).Rows.Count - 1)).ClearContents
'Format areas (col C to M)
With SelAreas(i).Interior
.ColorIndex = 37
.Pattern = xlSolid
End With
With SelAreas(i).Font
.ColorIndex = 3
.Bold = True
End With
Next i
'*
application.screenupdating = true
Exit Sub
NoTwosFound:
Selection.AutoFilter
MsgBox "There are no cells with the value of 2 in column R - now exiting sub without making any changes."
application.screenupdating = true
End Sub
--------------------


hth
Rob Brockett
NZ
Always learning & the best way to learn is to experience...


--
broro183
------------------------------------------------------------------------
broro183's Profile: http://www.excelforum.com/member.php...o&userid=30068
View this thread: http://www.excelforum.com/showthread...hreadid=508622

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
macro to change multiple values in a column mrwawa Excel Discussion (Misc queries) 7 July 2nd 06 04:35 PM
Need a Macro that will sum Values in a Column that are red havocdragon Excel Programming 9 October 15th 04 02:14 PM
macro to transpose cells in Column B based on unique values in Column A Aaron J. Excel Programming 3 October 8th 04 02:29 PM
How to activate the cell in same row, column 1? Sam Sieger Excel Programming 4 February 15th 04 01:07 AM
Transfer values from column to row using macro! aiyer Excel Programming 1 February 12th 04 12:21 AM


All times are GMT +1. The time now is 02:21 AM.

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

About Us

"It's about Microsoft Excel"