LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default variable not declared error & syntax error

Can anybody shed some light on this. I'm getting a variable not declared
error at:

wsTarget.Range("K1") = sum

When I take out the "Option Explicit" I then get a syntax error at:

Set SourceData = .Range(.Cells(SourceRowindex, "A"),

Here's my code which copies data from different sheets in the same workbook
to sheet1:


Option Explicit
Sub CopyData()
Dim wsTarget As Worksheet
Dim TargetRowindex As Long
Dim SourceRowindex As Long
Dim sheetindex As Long
Dim wsSource As Worksheet
Dim SourceData As Range
Set wsTarget = Worksheets("Sheet1")
wsTarget.Cells.ClearContents
wsTarget.Range("K1") = sum
For sheetindex = 2 To 9
Set wsSource = Worksheets("Sheet" & sheetindex)
SourceRowindex = 1
With wsSource
Do Until .Cells(SourceRowindex, "H") = ""
If .Cells(SourceRowindex, "H") < 100 Then
Set SourceData = .Range(.Cells(SourceRowindex, "A"),
..Cells(SourceRowindex, "I"))
TargetRowindex = TargetRowindex + 1
wsTarget.Range(wsTarget.Cells(TargetRowindex, "A"), _
wsTarget.Cells(TargetRowindex,
"I")).Value = _
SourceData.Value

End If

SourceRowindex = SourceRowindex + 1
Loop
End With
Next

End Sub



Any help would be greatly appreciated,
Gary


 
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
Deleting a range of rows based on a variable; syntax error Babymech Excel Discussion (Misc queries) 3 January 16th 09 06:19 PM
Reference a variable declared in VBA James Excel Worksheet Functions 3 September 12th 08 10:31 PM
Help on combining declared variable and cell formula sylink[_2_] Excel Programming 1 August 12th 05 10:09 PM
Help on combining declared variable and cell formula sylink Excel Programming 1 August 12th 05 07:58 PM
Syntax Error Runtime Error '424' Object Required sjenks183 Excel Programming 1 January 23rd 04 09:25 AM


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