Re: Need loop guidance

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Actually, I just tried the code and I'm getting a runtime error '13': Type
Mismatch message.

Any ideas?

Thanks,

"Ronald R. Dodge, Jr." wrote:

In this sort of case, you can setup an array variable instead of setting up
individual varable names.

Dim arrlngSP(30) As Long, arrlngTotal(30) As Long, I as Long

For I = 1 to 30 Step 1
arrlngSP(I) = Worksheets("data").Range("Line" & CStr(I) & "SP").Value
arrlngTotal(I) = Worksheets("data").Range("Line" & CStr(I) &
"tot").Value
Next I

In the above example, the " Step 1" isn't necessary as the default is
stepping one at a time going forward, but my general practice, I still like
to keep things about as explicit as one can be given issues I ran into in
the past with being implicit, not to mention changes that takes place from
one version to the next such as from VB6 to VB.NET.

Also, if your data type isn't long integer, then be sure to adjust your data
type and variable name appropriately as needed.

"Brad" <Brad@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1FE0FEA9-0217-4EB2-B687-D187EF5186BB@xxxxxxxxxxxxxxxx
Hello, I need assistance with creating code for a loop (which i'm not good
at
at all).

I have this code below that I'm only showing a portion of. I want to turn
this into a For Loop code because I have to do the below code from "SP1",
"Total1" through "SP30" and "Total30" so I'm looking at over 60 lines of
code.

How can I trun this into a For i = 1 to 30 type code? Any help is
appreciated.

Code:
SP1.Value = Sheets("data").Range("Line1SP").Value
Total1.Value = Sheets("data").Range("Line1tot").Value
SP2.Value = Sheets("data").Range("Line2SP").Value
Total2.Value = Sheets("data").Range("Line2tot").Value
SP3.Value = Sheets("data").Range("Line3SP").Value
Total3.Value = Sheets("data").Range("Line3tot").Value
SP4.Value = Sheets("data").Range("Line4SP").Value
Total4.Value = Sheets("data").Range("Line4tot").Value



.



Relevant Pages

  • Re: Need loop guidance
    ... "Ronald R. Dodge, Jr." ... Dim arrlngSPAs Long, arrlngTotalAs Long, I as Long ... Also, if your data type isn't long integer, then be sure to adjust your data ...
    (microsoft.public.excel.programming)
  • Re: Need loop guidance
    ... Mismatch message. ... "Ronald R. Dodge, Jr." ... Also, if your data type isn't long integer, then be sure to adjust your ...
    (microsoft.public.excel.programming)
  • Re: How can I get Atributes from the field of the table via VBA
    ... I think is data type in code ... "Brendan Reynolds" wrote: ... I don't know how you could get the caption and format, ... Dim tdf As DAO.TableDef ...
    (microsoft.public.access.adp.sqlserver)
  • RE: Dynamically declare and populate variables
    ... reason that I ask is that you can't declare variables as you describe. ... Declares an array of strings. ... Dim DataVarsAs Long ... Your array DataVars can only be 1 data type. ...
    (microsoft.public.excel.programming)
  • Re: new to coding
    ... I think John was wondering why you were using VB6 Express edition rather ... Integer is the correct data type to use. ... Dim one As String = "1" ...
    (microsoft.public.dotnet.general)