+ Reply to Thread
Results 1 to 4 of 4

What Am I doing wrong here?

Hybrid View

  1. #1
    Registered User
    Join Date
    05-31-2007
    Posts
    24

    What Am I doing wrong here?

    Greetings,

    On the below code, its breaking at exactly the same spot, I cant for the life of me figure out why.

    I get VB 400 error or 1004 error depending on which line you remove the comment ' from

    Sub WhatsWrong()
    Dim i As Integer, j As Integer, k As integer
    Dim eName As String, SaTotal As String
    
        For j = 3 to 15
           SaTotal = "=Sum"
               For i = 4 to ThisWorkBook.Sheets("Master Edit").Range("C" & Rows.Count).End(xlUp).Row
                   eName = ThisWorkBook.Sheets(Master Edit).Range("C" & i).Value
                   SaTotal =SaTotal + "(" & eName & "!$B$" & j & ")"
               Next i
         k = j + 1
    
             ThisWorkBook.Sheets("Master Edit").Range("A1").Select 'trying to get the activesheet
    
              MsgBox "The resulting formula for cell (F" & k & ")" & SaTotal
    
            With ActiveSheet
             .Range(k, 6).Value = SaTotal
           '  .Cell(k, 6).Value = SaTotal
           '  .Range("F" & k).Value = SaTotal
            End With
    
           '   ThisWorkBook.Sheets("Annual Report").Range("F" & k).Value = SaTotal
        
     Next j
    I've tried all combinations of the code listed here, commenting out as required.

    Its still breaking..

    The Message Box indicats the CORRECT formula I am after is being generated.

    Any Clues?

    Aurbo99

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    The syntax is Cells (plural)
    I can't see why the string based Ranges are erroring, I'd try
    Range("F" & CStr(k))
    or changing to this
    SaTotal =SaTotal & "(" & eName & "!$B$" & j & ")"
    I'm not sure why it isn't erroring with the plus sign.

  3. #3
    Registered User
    Join Date
    05-31-2007
    Posts
    24
    Thanks Mike,

    I've changed the + to an &

    the formula still looks correct after that change,

    The CStr(k)) had no change in the error.

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Try this.


    Sub WhatsWrong()
    Dim i As Integer, j As Integer, k As Integer
    Dim eName As String, SaTotal As String
    
        For j = 3 To 15
           SaTotal = "=Sum(" '*** changed
               For i = 4 To ThisWorkbook.Sheets("Master Edit").Range("C" & Rows.Count).End(xlUp).Row
                   eName = ThisWorkbook.Sheets("Master Edit").Range("C" & i).Value '********** Change here
                   SaTotal = SaTotal & eName & "!$B$" & j & ","  '***change
               Next i
         k = j + 1
    
             ThisWorkbook.Sheets("Master Edit").Range("A1").Select 'trying to get the activesheet
              SaTotal = Left(SaTotal, Len(SaTotal) - 1) & ")"  '*** new line
              MsgBox "The resulting formula for cell (F" & k & ")" & SaTotal
            
            With ActiveSheet
            ' .Range(k, 6).Value = SaTotal
            .Cells(k, 6).Formula = SaTotal '*** new line
           '  .Cell(k, 6).Value = SaTotal
           '  .Range("F" & k).Value = SaTotal
            End With
    
           '   ThisWorkBook.Sheets("Annual Report").Range("F" & k).Value = SaTotal
        
     Next j
    End Sub

    rylo

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1