Run macro only if Worksheet("Individual").cells(7,1) is the

G

Guest

Guest
I am trying to constrict the use of this macro so that it will only run if cell A7 on a sheet called individual has been selected. The macro will be started by pressing CTRL I so I do not want it to run only if the cell is clicked on.
Any other comments on the macro that may stop things falling apart most welcome.

Sub new_Wb()
'
' new_Wb Macro
' Macro recorded 11/03/2002 by gj
'

'
'If Worksheets("Individual").Cells(7, 1) = ActiveCell Then

Worksheets.Copy


Sheets("Individual").Select

Set ToWS = Worksheets("Individual")
Set SRV = Worksheets("Settled RV")
Dim SheetName As String

With Worksheets("Listing")

For irow = 3 To .UsedRange.Row + .UsedRange.Rows.Count - 1


If Not .Cells(irow, 1) = .Cells(2, 1) Then
.Cells(irow, 1).Copy Destination:=ToWS.Cells(7, 1)

ToWS.Cells(7, 1).ShrinkToFit = False


PropertyName = ToWS.Cells(7, 1)

ToWS.Select
Cells.Select
Selection.Copy
Sheets.Add
Selection.PasteSpecial Paste:=xlValues
Selection.PasteSpecial Paste:=xlFormats


If Len(PropertyName) > 31 Then
SheetName = Left(PropertyName, 22) & ".." & Right(PropertyName, 6)
Else
SheetName = Left(PropertyName, 31)
End If

For i = 1 To Len(SheetName)
strChr = Mid(SheetName, i, 1)
Select Case strChr
Case Chr(42), Chr(47), Chr(58), Chr(63), Chr(92)
strtemp = strtemp & "-"
Case Else
strtemp = strtemp & strChr
End Select
Next i

SheetName = strtemp

ActiveSheet.Name = SheetName
SheetName = " "
strtemp = " "

ActiveSheet.Cells(7, 1).Select


End If


Next irow

End With

Worksheets(Array("Info", "Totals", "Settled RV", "Individual")).Visible = xlHidden



Dim oSht As Object 'deletes all hidden sheets
Application.DisplayAlerts = False 'suppress delete warning
For Each oSht In Sheets
If Not oSht.Visible Then oSht.Delete
Next
Application.DisplayAlerts = True

'End If

End Sub


:cool: :cool: :LOL:
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
This question is asked by George J

For some reason my details were not pulled through even though i was logged in. This message is so that I can find the thread at a later date.
 
Upvote 0
Thanks goes to Bill Jelen for the solution

Start the macro with this if statement:

If not ActiveSheet.Name = "Individual" then exit sub
If not ActiveCell.Address = Range "A7").Address exit sub

This will insure that the macro only runs when the user has A7 activated.

Bill

:biggrin: :biggrin: :biggrin: :biggrin: :LOL:
 
Upvote 0

Forum statistics

Threads
1,214,545
Messages
6,120,128
Members
448,947
Latest member
test111

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top