#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,814
Default Help with Syntax

In the code below, I'm getting an error when I get to:

curWks.Cells(iRow, "A") = sh.Cells(1, colvalue).Value

---------------------------------------------------------------
Sub Data_Dump()

Dim curWks, ws As Worksheet
Dim FirstRow, Lastrow, Rowloop, colval As Integer

Application.ScreenUpdating = False
Set curWks = Worksheets("Data")
Set sh = Worksheets("All States")
curWks.Range("A2:D11376").Clear
iRow = 2
sh.Activate
For colval = 5 To 39
FirstRow = 2
Lastrow = 28
For Row_Loop = FirstRow To Lastrow
curWks.Cells(iRow, "A") = sh.Cells(1, colvalue).Value
curWks.Cells(iRow, "B") = sh.Cells(Row_Loop, 4).Value
curWks.Cells(iRow, "C") = sh.Cells(Row_Loop, colval).Value
iRow = iRow + 1
Next 'for
Next 'for
Application.ScreenUpdating = True

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Help with Syntax

Steve,

The problem is likely that you have a variable declared as "colval" but your
code is using "colvalue". You would not have encountered this problem --
the compiler would have caught it -- if you used "Option Explicit" at the
very top of the code module. See http://www.cpearson.com/excel/variables.htm
for information about declaring variables.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Steve" wrote in message
...
In the code below, I'm getting an error when I get to:

curWks.Cells(iRow, "A") = sh.Cells(1, colvalue).Value

---------------------------------------------------------------
Sub Data_Dump()

Dim curWks, ws As Worksheet
Dim FirstRow, Lastrow, Rowloop, colval As Integer

Application.ScreenUpdating = False
Set curWks = Worksheets("Data")
Set sh = Worksheets("All States")
curWks.Range("A2:D11376").Clear
iRow = 2
sh.Activate
For colval = 5 To 39
FirstRow = 2
Lastrow = 28
For Row_Loop = FirstRow To Lastrow
curWks.Cells(iRow, "A") = sh.Cells(1, colvalue).Value
curWks.Cells(iRow, "B") = sh.Cells(Row_Loop, 4).Value
curWks.Cells(iRow, "C") = sh.Cells(Row_Loop, colval).Value
iRow = iRow + 1
Next 'for
Next 'for
Application.ScreenUpdating = True

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,339
Default Help with Syntax

typo .......

curWks.Cells(iRow, "A") = sh.Cells(1, colval).Value

"Steve" wrote:

In the code below, I'm getting an error when I get to:

curWks.Cells(iRow, "A") = sh.Cells(1, colvalue).Value

---------------------------------------------------------------
Sub Data_Dump()

Dim curWks, ws As Worksheet
Dim FirstRow, Lastrow, Rowloop, colval As Integer

Application.ScreenUpdating = False
Set curWks = Worksheets("Data")
Set sh = Worksheets("All States")
curWks.Range("A2:D11376").Clear
iRow = 2
sh.Activate
For colval = 5 To 39
FirstRow = 2
Lastrow = 28
For Row_Loop = FirstRow To Lastrow
curWks.Cells(iRow, "A") = sh.Cells(1, colvalue).Value
curWks.Cells(iRow, "B") = sh.Cells(Row_Loop, 4).Value
curWks.Cells(iRow, "C") = sh.Cells(Row_Loop, colval).Value
iRow = iRow + 1
Next 'for
Next 'for
Application.ScreenUpdating = True

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
SQL syntax Spike Excel Worksheet Functions 2 March 8th 07 08:27 AM
syntax correction Richard Excel Worksheet Functions 4 February 14th 07 08:30 PM
VBA syntax Sunantoro Excel Discussion (Misc queries) 1 September 21st 05 03:19 AM
If then syntax RL Excel Worksheet Functions 3 June 22nd 05 05:30 AM
Syntax Help Dmorri254 Excel Worksheet Functions 2 March 2nd 05 02:51 PM


All times are GMT +1. The time now is 05:29 PM.

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"