Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() I am entering info given to me here on the Forum, I am getting an error and this line is highlighted. For Each myCell In myRange.Cells I don't know VBA or Macro and am trying to figure it out on my own. These are the formulas I have been given: Option Explicit Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim myCell As Range Dim myRange As Range Set myRange = Nothing On Error Resume Next Set myRange = Me.Range("MustFill") On Error GoTo 0 If myRange Is Nothing Then MsgBox "Please contact CBrausa at #### to fix the MustFill Range" Exit Sub End If For Each myCell In myRange.Cells If myCell.Address = myCell.MergeArea.Cells(1).Address Then If myCell.Value = "" ThenApplication.EnableEvents = False myCell.Select Application.EnableEvents = True Exit For End If End If Next myCell End Sub And for the string of cells I need this to apply to: An alternative way to setting a range is to use a macro: Option Explicit Sub testme() With worksheets("sheet999") '<--- .Range("T4,E5,M5,T7,E8,M8,E14,M14,D16,M16,D18," _ & "M18,L19,M20,N21,U21,N23,B24,K29,B30,L31,B33," _ & "I33,B35,B39,B43,B45,F47,K47,P47,S47,V47,Y47,B 49," _ & "T52,I53,I54,I55,H56,I58,Q50,S55,S56,S57").Nam e _ = "'" & .Name & "'!mustfill" End With End Sub Change the worksheet name to match. (to match what?) What am I doing wrong? -- CBrausa ------------------------------------------------------------------------ CBrausa's Profile: http://www.excelforum.com/member.php...o&userid=24677 View this thread: http://www.excelforum.com/showthread...hreadid=543367 |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I don't understand why that line causes an error.
But this note: "Change the worksheet name to match. (to match what?)" is an instruction to change Sheet999 in this line: With worksheets("sheet999") '<--- to the name of the worksheet that has those cells that must be filled in. CBrausa wrote: I am entering info given to me here on the Forum, I am getting an error and this line is highlighted. For Each myCell In myRange.Cells I don't know VBA or Macro and am trying to figure it out on my own. These are the formulas I have been given: Option Explicit Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim myCell As Range Dim myRange As Range Set myRange = Nothing On Error Resume Next Set myRange = Me.Range("MustFill") On Error GoTo 0 If myRange Is Nothing Then MsgBox "Please contact CBrausa at #### to fix the MustFill Range" Exit Sub End If For Each myCell In myRange.Cells If myCell.Address = myCell.MergeArea.Cells(1).Address Then If myCell.Value = "" ThenApplication.EnableEvents = False myCell.Select Application.EnableEvents = True Exit For End If End If Next myCell End Sub And for the string of cells I need this to apply to: An alternative way to setting a range is to use a macro: Option Explicit Sub testme() With worksheets("sheet999") '<--- Range("T4,E5,M5,T7,E8,M8,E14,M14,D16,M16,D18," _ & "M18,L19,M20,N21,U21,N23,B24,K29,B30,L31,B33," _ & "I33,B35,B39,B43,B45,F47,K47,P47,S47,V47,Y47,B 49," _ & "T52,I53,I54,I55,H56,I58,Q50,S55,S56,S57").Nam e _ = "'" & .Name & "'!mustfill" End With End Sub Change the worksheet name to match. (to match what?) What am I doing wrong? -- CBrausa ------------------------------------------------------------------------ CBrausa's Profile: http://www.excelforum.com/member.php...o&userid=24677 View this thread: http://www.excelforum.com/showthread...hreadid=543367 -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() I changed the sheet name, reset, and it gives me the error and highlights that line -- CBrausa ------------------------------------------------------------------------ CBrausa's Profile: http://www.excelforum.com/member.php...o&userid=24677 View this thread: http://www.excelforum.com/showthread...hreadid=543367 |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Which line. The same one as before or "With worksheets("sheet999") '<--- " If
it is be sure you left the Quotes in the Paranthesis. It would help if you gave us what the Error said. Also you will need to delete the space in the line & "T52,I53,I54,I55,H56,I58,Q50,S55,S56,S57").Nam e _ Change Nam e to Name "CBrausa" wrote: I changed the sheet name, reset, and it gives me the error and highlights that line -- CBrausa ------------------------------------------------------------------------ CBrausa's Profile: http://www.excelforum.com/member.php...o&userid=24677 View this thread: http://www.excelforum.com/showthread...hreadid=543367 |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() The error message reads: Compile Error: Only comments may appear after End Sub, End Function, Or End Property. I highlighted the line in Red. Option Explicit Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim myCell As Range Dim myRange As Range Set myRange = Nothing On Error Resume Next Set myRange = Me.Range("MustFill") On Error GoTo 0 If myRange Is Nothing Then MsgBox "Please contact CBrausa at #### to fix the MustFill Range" Exit Sub End If For Each myCell In myRange.Cells If myCell.Address = myCell.MergeArea.Cells(1).Address Then If myCell.Value = "" Then Application.EnableEvents = False myCell.Select Application.EnableEvents = True Exit For End If End If Next myCell End Sub -- CBrausa ------------------------------------------------------------------------ CBrausa's Profile: http://www.excelforum.com/member.php...o&userid=24677 View this thread: http://www.excelforum.com/showthread...hreadid=543367 |
#6
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
You may have highlighted the line in red, but in a plain text newsgroup like
this, it can't be seen. Make sure that there are no extra characters after the "End Sub" line. CBrausa wrote: The error message reads: Compile Error: Only comments may appear after End Sub, End Function, Or End Property. I highlighted the line in Red. Option Explicit Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim myCell As Range Dim myRange As Range Set myRange = Nothing On Error Resume Next Set myRange = Me.Range("MustFill") On Error GoTo 0 If myRange Is Nothing Then MsgBox "Please contact CBrausa at #### to fix the MustFill Range" Exit Sub End If For Each myCell In myRange.Cells If myCell.Address = myCell.MergeArea.Cells(1).Address Then If myCell.Value = "" Then Application.EnableEvents = False myCell.Select Application.EnableEvents = True Exit For End If End If Next myCell End Sub -- CBrausa ------------------------------------------------------------------------ CBrausa's Profile: http://www.excelforum.com/member.php...o&userid=24677 View this thread: http://www.excelforum.com/showthread...hreadid=543367 -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Search, Copy, Paste Macro in Excel | Excel Worksheet Functions | |||
Closing File Error | Excel Discussion (Misc queries) | |||
macro with F9 | Excel Discussion (Misc queries) | |||
Make Alignment options under format cells available as shortcut | Excel Discussion (Misc queries) | |||
Playing a macro from another workbook | Excel Discussion (Misc queries) |