#1   Report Post  
Posted to microsoft.public.excel.misc
CBrausa
 
Posts: n/a
Default Macro help


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   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Macro help

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   Report Post  
Posted to microsoft.public.excel.misc
CBrausa
 
Posts: n/a
Default Macro help


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   Report Post  
Posted to microsoft.public.excel.misc
Abode
 
Posts: n/a
Default Macro help

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   Report Post  
Posted to microsoft.public.excel.misc
CBrausa
 
Posts: n/a
Default Macro help


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   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Macro help

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
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
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
macro with F9 Kenny Excel Discussion (Misc queries) 1 August 3rd 05 02:41 PM
Make Alignment options under format cells available as shortcut dforrest Excel Discussion (Misc queries) 1 July 14th 05 10:58 PM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM


All times are GMT +1. The time now is 07:44 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"