Run macro using one of a number of cells
Solved/Closed
craigo
Posts
19
Registration date
Friday February 27, 2009
Status
Member
Last seen
April 4, 2009
-
Feb 28, 2009 at 08:17 AM
sam - Aug 19, 2009 at 07:57 AM
sam - Aug 19, 2009 at 07:57 AM
Related:
- Run macro using one of a number of cells
- Spell number in excel without macro - Guide
- Excel macro to create new sheet based on value in cells - Guide
- Count if cell contains number - Excel Forum
- How would you change all cells containing the word pass to green - Excel Forum
- If a cell has text then return value ✓ - Excel Forum
4 responses
See if this gets you in the right direction. Hope it helps!
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range
Dim IntersectRange As Range
Set MyRange = Range("A35:A600")
Set IntersectRange = Intersect(Target, MyRange)
If IntersectRange Is Nothing Then
Exit Sub
Else: Call Macro1
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range
Dim IntersectRange As Range
Set MyRange = Range("A35:A600")
Set IntersectRange = Intersect(Target, MyRange)
If IntersectRange Is Nothing Then
Exit Sub
Else: Call Macro1
End If
End Sub
craigo
Posts
19
Registration date
Friday February 27, 2009
Status
Member
Last seen
April 4, 2009
1
Mar 2, 2009 at 12:36 PM
Mar 2, 2009 at 12:36 PM
You're an absolute star, thank you so much, it works perfectly, very grateful :-)
craigo
Posts
19
Registration date
Friday February 27, 2009
Status
Member
Last seen
April 4, 2009
1
Mar 1, 2009 at 05:53 AM
Mar 1, 2009 at 05:53 AM
Hi,
Thanks for your reply, I've tried the code you gave me but it doesn't work, it doesn't come up with any errors either, nothing happens at all, any ideas?
Craig
Thanks for your reply, I've tried the code you gave me but it doesn't work, it doesn't come up with any errors either, nothing happens at all, any ideas?
Craig
craigo
Posts
19
Registration date
Friday February 27, 2009
Status
Member
Last seen
April 4, 2009
1
Mar 1, 2009 at 01:40 PM
Mar 1, 2009 at 01:40 PM
Thats absolutely perfect, thank you very much.
The next problem I've encountered is with the macro itself. I'm trying to move the active cell over to the right one cell and copy that and the further 10 cells to the right. I've managed to move the activated cell with the offset command but can't get it to copy all the cells?
Sub Macro1()
'
' Macro1 Macro
'
'
ActiveSheet.Unprotect
ActiveCell.Offset(0, 1).Select
Selection.Copy
Range("B2").Select
ActiveSheet.Paste
Rows("2:2").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Rows("3:3").Select
Selection.Copy
Rows("2:2").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
The next problem I've encountered is with the macro itself. I'm trying to move the active cell over to the right one cell and copy that and the further 10 cells to the right. I've managed to move the activated cell with the offset command but can't get it to copy all the cells?
Sub Macro1()
'
' Macro1 Macro
'
'
ActiveSheet.Unprotect
ActiveCell.Offset(0, 1).Select
Selection.Copy
Range("B2").Select
ActiveSheet.Paste
Rows("2:2").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Rows("3:3").Select
Selection.Copy
Rows("2:2").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Does this work for you?
Sub Macro1()
Dim j
j = 2
ActiveSheet.Unprotect
Cells(j, 2) = ActiveCell.Offset(0, 1).Value
Cells(j, 3) = ActiveCell.Offset(0, 2).Value
Cells(j, 4) = ActiveCell.Offset(0, 3).Value
Cells(j, 5) = ActiveCell.Offset(0, 4).Value
Cells(j, 6) = ActiveCell.Offset(0, 5).Value
Cells(j, 7) = ActiveCell.Offset(0, 6).Value
Cells(j, 8) = ActiveCell.Offset(0, 7).Value
Cells(j, 9) = ActiveCell.Offset(0, 8).Value
Cells(j, 10) = ActiveCell.Offset(0, 9).Value
Cells(j, 11) = ActiveCell.Offset(0, 10).Value
Rows("2:2").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Rows("3:3").Select
Selection.Copy
Rows("2:2").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Sub Macro1()
Dim j
j = 2
ActiveSheet.Unprotect
Cells(j, 2) = ActiveCell.Offset(0, 1).Value
Cells(j, 3) = ActiveCell.Offset(0, 2).Value
Cells(j, 4) = ActiveCell.Offset(0, 3).Value
Cells(j, 5) = ActiveCell.Offset(0, 4).Value
Cells(j, 6) = ActiveCell.Offset(0, 5).Value
Cells(j, 7) = ActiveCell.Offset(0, 6).Value
Cells(j, 8) = ActiveCell.Offset(0, 7).Value
Cells(j, 9) = ActiveCell.Offset(0, 8).Value
Cells(j, 10) = ActiveCell.Offset(0, 9).Value
Cells(j, 11) = ActiveCell.Offset(0, 10).Value
Rows("2:2").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Rows("3:3").Select
Selection.Copy
Rows("2:2").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Hi,
I tried from all your list of codes. I could not solve a problem.
I need a code were any cell in the sheet if i change the existing value the color should change in that Cell.
Like if A1 cell already have a data 20 and it is in green color. When i change the value of A1 cell to 25 it should change to Red color.
I tried
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 1 Then Target.Interior.ColorIndex = 3
End Sub
this works only on the first row how can it work on the entire sheet, Can u please help me
I tried from all your list of codes. I could not solve a problem.
I need a code were any cell in the sheet if i change the existing value the color should change in that Cell.
Like if A1 cell already have a data 20 and it is in green color. When i change the value of A1 cell to 25 it should change to Red color.
I tried
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 1 Then Target.Interior.ColorIndex = 3
End Sub
this works only on the first row how can it work on the entire sheet, Can u please help me