Wrox Programmer Forums
|
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 September 26th, 2005, 03:34 PM
Registered User
 
Join Date: Sep 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default where is the error?

Hi all,
this is my first time here =)

last week i did some changes in an excel workbook that i'll use to calculate the torsional stiffness in a twin tube chassis frame.

The code works well but when i exit the Excel program a message pop ups saying "runtime error 1004" method Cells of object _Global fails.

i have no idea what this means because i did some program in Fortran but this is my first experience with VB

i repeat that the code works great but i'm too curios to find where i did wrong...

here follows the code:

Sub Sostituisci1(j)
    Dim count As Integer
    Dim i As Integer
    i = 0
    count = 0
    Do Until count = 20
        If Cells(4, 3).Value = count Then
            Do Until i = 10
                Worksheets(2).Cells((28+(count * 15))+i, 3+j).Copy
                Worksheets(2).Cells(5 + i, 3).Select
                Worksheets(2).Paste
            i = i + 1
            Loop
            Exit Do
        End If
        count = count + 1
    Loop
End Sub


the debug button point at that line:

 If Cells(4, 3).Value = count Then

but for me it seems all ok! where i'm wrong?

tnx for the help

Matteo Valentini
Modena - Italy



 
Old September 27th, 2005, 02:08 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it appears that you are passing a value as j, this is giving a clue but I hope not a red herring, because you are passing into the procedure 'j' can you tell me how this procedure becomes executed, is it through the use of a command button on the worksheet? or are you controlling this via a user form, I think we need more info to proceed.


cheers

Matthew Paba (English/Italian Citizen)
Poole, Dorset, England

 
Old September 27th, 2005, 11:20 AM
Registered User
 
Join Date: Sep 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok i'll try to explain it better.

i have a sets of data made by four columns of data, one column for each tire of the car.
i need to load one set using a ComboBox then with 4 switch buttons i need to choose the data column of each tire.

in the combo box there is the following code:

Private Sub ComboBox1_Change()
   Dim j as Integer
   j=0
   Sostituisci(j)
End sub

this code call the subroutine sostituisci(j) with the j variable set to 0 that means that the default column loaded is the one corresponding to the left front wheel.

now i must be able to change the wheel keeping loaded this set so i put four option button with this code:

Private sub OptionButton_Click()
   Dim FrontRight as integer
   FrontRight = 2
   sostituisci(2)
end Sub

obviously the code is the same for the other 3 button except for the value of the variable which goes from 0 to 3 and this is explained in the following command line of the sostituisci subroutine

WorkSheets(2).Cells((28+(count*15))+i,3+j).Copy

where count is the variable which points at the set of data (0<count<20) and i is the variable which points at the columns in those particular set (0<i<10).
j is the number of the column to print and it goes from 0 (leftFront) to 3 (rightRear)

i hope u'll understand... but it's difficult for me to explain it in italian guess in english

Matteo Valentini
Modena - Italy

 
Old September 28th, 2005, 02:28 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ciao Matteo

May I suggest the following code changes,

in the original code can you change it to the following,

    Dim count As Integer
    Dim i As Integer
    i = 0
    count = 0
    Do Until count = 20
        If Cells(4, 3).Value = count Then
            Do Until i = 10
                Worksheets(2).Cells((28 + (count * 15)) + i, 3 + j).Copy
                Worksheets(2).Select 'changed
                Cells(5 + i, 3).Select 'changed
                ActiveCell.PasteSpecial
            i = i + 1
            Loop
            Exit Do
        End If
        count = count + 1
    Loop

the 2 lines that have changed were causing me an error in the code, unfortunately I cant replicate your error yet.

I might suggest you send the workbook to me and I will have a look with you if you want? email - [email protected]


cheers

Matt

PS Ferrari, Lambo, or Maserati or other (just being nosey)?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
[Resolved] Error calling a sp - parameter error snufse .NET Framework 2.0 2 February 12th, 2008 04:46 PM
Parse error: syntax error, unexpected T_STRING ginost7 Beginning PHP 1 November 9th, 2007 02:51 AM
Phile Page error, visual studio error reps BOOK: ASP.NET Website Programming Problem-Design-Solution 0 September 27th, 2003 10:11 AM





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