Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 163
Default Excel 2003 + help please with button

Hi all, can anyone tell me why i'm getting a Compile Error: Syntax Error on
the line:

For lng = 0 me.ListBox1.listcount - 1?

Thanks.

Sub Button2_Click()

Dim lng As Long
Dim col As Collection
Dim wb2 As Workbook
Dim ws As Worksheet

Set col = New Collection
For lng = 0 Me.Neil.ListCount - 1
If Me.ListBox1.Selected(lng) Then
col.Add Me.ListBox1.List(lng)
End If
Next lng

If col.Count = 0 Then
MsgBox "No Selections"
Else
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set wb1 = ActiveWorkbook
Set wb2 = Workbooks.Open("\\sguk-app1\Business Objects\CHR\Export of
SGUK.xls ")
Set ws = wb2.Sheets("Sheet1")

For Each wks In col
wks.Range("A8:T27").Copy ws.Cells(Rows.Count,
"A").End(xlUp).Offset(1, 0)
Next wks
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End If


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,389
Default Excel 2003 + help please with button

Your For statement has no "To". Try:
For lng = 0 To Me.Neil.ListCount - 1

Regards,
Fred

"Neil Holden" wrote in message
...
Hi all, can anyone tell me why i'm getting a Compile Error: Syntax Error
on
the line:

For lng = 0 me.ListBox1.listcount - 1?

Thanks.

Sub Button2_Click()

Dim lng As Long
Dim col As Collection
Dim wb2 As Workbook
Dim ws As Worksheet

Set col = New Collection
For lng = 0 Me.Neil.ListCount - 1
If Me.ListBox1.Selected(lng) Then
col.Add Me.ListBox1.List(lng)
End If
Next lng

If col.Count = 0 Then
MsgBox "No Selections"
Else
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set wb1 = ActiveWorkbook
Set wb2 = Workbooks.Open("\\sguk-app1\Business Objects\CHR\Export
of
SGUK.xls ")
Set ws = wb2.Sheets("Sheet1")

For Each wks In col
wks.Range("A8:T27").Copy ws.Cells(Rows.Count,
"A").End(xlUp).Offset(1, 0)
Next wks
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End If


End Sub


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Excel 2003 + help please with button

You need "to"

For lng = 0 to Me.Neil.ListCount - 1

--
Gary''s Student - gsnu201001
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 163
Default Excel 2003 + help please with button

I've tried that and still getting errors, thanks for your help though.

Neil.

"Fred Smith" wrote:

Your For statement has no "To". Try:
For lng = 0 To Me.Neil.ListCount - 1

Regards,
Fred

"Neil Holden" wrote in message
...
Hi all, can anyone tell me why i'm getting a Compile Error: Syntax Error
on
the line:

For lng = 0 me.ListBox1.listcount - 1?

Thanks.

Sub Button2_Click()

Dim lng As Long
Dim col As Collection
Dim wb2 As Workbook
Dim ws As Worksheet

Set col = New Collection
For lng = 0 Me.Neil.ListCount - 1
If Me.ListBox1.Selected(lng) Then
col.Add Me.ListBox1.List(lng)
End If
Next lng

If col.Count = 0 Then
MsgBox "No Selections"
Else
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set wb1 = ActiveWorkbook
Set wb2 = Workbooks.Open("\\sguk-app1\Business Objects\CHR\Export
of
SGUK.xls ")
Set ws = wb2.Sheets("Sheet1")

For Each wks In col
wks.Range("A8:T27").Copy ws.Cells(Rows.Count,
"A").End(xlUp).Offset(1, 0)
Next wks
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End If


End Sub


.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,389
Default Excel 2003 + help please with button

It worked for me when I put it into the VBA Editor. Did you copy and paste
it?

Regards,
Fred

"Neil Holden" wrote in message
...
I've tried that and still getting errors, thanks for your help though.

Neil.

"Fred Smith" wrote:

Your For statement has no "To". Try:
For lng = 0 To Me.Neil.ListCount - 1

Regards,
Fred

"Neil Holden" wrote in message
...
Hi all, can anyone tell me why i'm getting a Compile Error: Syntax
Error
on
the line:

For lng = 0 me.ListBox1.listcount - 1?

Thanks.

Sub Button2_Click()

Dim lng As Long
Dim col As Collection
Dim wb2 As Workbook
Dim ws As Worksheet

Set col = New Collection
For lng = 0 Me.Neil.ListCount - 1
If Me.ListBox1.Selected(lng) Then
col.Add Me.ListBox1.List(lng)
End If
Next lng

If col.Count = 0 Then
MsgBox "No Selections"
Else
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set wb1 = ActiveWorkbook
Set wb2 = Workbooks.Open("\\sguk-app1\Business
Objects\CHR\Export
of
SGUK.xls ")
Set ws = wb2.Sheets("Sheet1")

For Each wks In col
wks.Range("A8:T27").Copy ws.Cells(Rows.Count,
"A").End(xlUp).Offset(1, 0)
Next wks
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End If


End Sub


.


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
How do I add a password button to 2003 Excel? Pete Excel Discussion (Misc queries) 1 September 11th 09 03:06 PM
Excel 2003 - clear button dow Excel Discussion (Misc queries) 3 November 9th 07 02:09 PM
Themes button in Excel 2003 TLC Excel Discussion (Misc queries) 1 September 19th 07 09:44 PM
Excel 2003 REDO Button L J Leovic Excel Worksheet Functions 1 January 17th 05 01:54 AM
Fx button in Excel 2003 cj Excel Worksheet Functions 2 December 9th 04 02:45 PM


All times are GMT +1. The time now is 08:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"