+ Reply to Thread
Results 1 to 2 of 2

VBA cell assignments won't work? WHY?

Hybrid View

  1. #1
    Registered User
    Join Date
    01-20-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    30

    VBA cell assignments won't work? WHY?

    this macro is hypothetically going to find the widest entry in each column, and then write that width in a new inserted top row. My problem is it doesn't like my cell assignments (even when they are exactly like cell assignments I've done in the past! any idea why it hates this line no matter how I program it?

            ActiveSheet.Cells(0, ccount) = 0
            ActiveSheet.Cells(0, ccount).Value = 0
            Cells(0, ccount) = 0
            Cells(0, ccount).Value = 0
    Full code is this

    Sub WidthCounter()
        Rows("1:1").Select
        Dim ccount As Integer
        ccount = Selection.Cells.SpecialCells(xlCellTypeConstants).Count
        MsgBox (ccount)
        Columns("A:A").Select
        Dim rcount As Integer
        rcount = Selection.Cells.SpecialCells(xlCellTypeConstants).Count
        MsgBox (rcount)
        ActiveCell.EntireRow.Insert
        rcount = rcount + 1
        
        For a_counter = 1 To ccount
            ActiveSheet.Cells(0, ccount) = 0 
            For b_counter = 2 To rcount
               temp = Len(Cells(rcount, ccount).Value)
               If (temp > Cells(0, ccount).Value) Then Cells(0, ccount).Value = temp
            Next b_counter
        Next a_counter
    
    End Sub
    Last edited by scantron; 05-14-2012 at 01:30 PM.

  2. #2
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: VBA cell assignments won't work? WHY?

    The top left corner of an active worksheet is Cells(1,1).

+ 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