How to restrict macro execution to a column subset?

M

macurious

I have recorded a macro which does several find & replace text function. I
would like it to perform these function only on a specific column; not the
entire spreadsheet. What is the macro syntax for doing this?
 
D

damorrison

This is just an example of what I have, when I right click on the mouse
a userform shows, this only works in column A


Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)
If Union(Range("$A:$A"), Target).Address = Range("$A:$A").Address Then
userform1.Show
Cancel = True
End If
End Sub
 
C

Chip Pearson

If Union(Range("$A:$A"), Target).Address =
Range("$A:$A").Address Then

That's rather cumbersome code. Why not just

If Target.Column = 1 Then


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
D

damorrison

THAT'S GREAT,
1 meaning column A of course
and then an End If
How come I ended up with the other code, I don't know!!
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top