Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 28th, 2013, 11:08 AM
Registered User
 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default coding issue: a belgian chocolate box as a gift for the hero !

Hello everyone ! (PS. I ll really send a box of chocolate cause I have this issue for a while now!)

Here is my issue: I have datas from 1 to 100 (lines) ans 1 to 261 columns
With those datas I want to create a matrix, called matrix_lockin (i,j)

only when the IF is true, the value must be equal to the cell
but when it's not true, all the rest of the line must be equal to 0,03

for instance, for the first line of my matrix:
0,10 0,14 0,03 0,03 till the end

then we need to do the same for the next i

so when if is false, I had to create another FOR loop , especially for the the J
but when I used J, it said "cotnrol variable already in use".. SO I changed it to k... When all the k are done, I need to jump out of the for loop so that i can do the same for the i...

that's why I put a EXIT for ...

The code is below.


The problem isThe first line of my matrix is perfect but the rest of the line are exactly the same as the first line (i = ligne)

And as soon as the debug reaches the first line of my sub
: Static Sub lockin(nb_pas As Integer)

the matrix lockin has already datas inside (all the lines are the first line)
I don't understand at all the debugging part.


Thanks a lot in advance !

Code:
For i = 1 To nb_pas
    For j = 1 To 261
        If Cells(4, 1 + j) < 0.22 Then
            matrice_lockin(i, j) = Cells(4, 1 + j)
        Else
            For k = j To 261
                matrice_lockin(i, k) = 0.03
            Next k
            Exit For
        End If
    Next j
Next i
 
Old March 3rd, 2013, 09:56 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Try replacing

Code:
        If Cells(4, 1 + j) < 0.22 Then
            matrice_lockin(i, j) = Cells(4, 1 + j)
with

Code:
        If Cells(i, 1 + j) < 0.22 Then
            matrice_lockin(i, j) = Cells(i, 1 + j)
Hope the hard-coded '4' is the problem

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
coding problem in common dialog box cancertropica Visual Basic 2005 Basics 0 July 30th, 2008 09:38 AM
chap10 - If a hero has no enemies bill_the_cat BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 May 25th, 2008 05:17 AM
issue with combo box manish_msh Struts 1 June 4th, 2007 10:56 PM
Coding issue ebburks Access 3 June 4th, 2006 01:39 AM
Multi Select List Box Coding Errors... snoopy92211 VB Databases Basics 10 June 30th, 2004 08:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.