Consulting

Results 1 to 5 of 5

Thread: Solved: macro doesn't work

  1. #1

    Solved: macro doesn't work

    I am trying to write a code that runs certain macros until the last used cell in column A. The code is not working could anybody help me with this?

    HTML Code:
    Sub ds()
    
    
    Dim i As Integer
    Dim intRowCount As Integer
    
    
    intRowCount = Range("A2").CurrentRegion.Rows.Count - 1
    For i = 2 To intRowCount
    
    If Not Cells(i, 1).Value = "" Then
    TextBox1.Value = Cells(i, 1).Value
    TextBox2.Value = Cells(i, 2).Value
    TextBox3.Value = Cells(i, 3).Value
    TextBox4.Value = Cells(i, 4).Value
    
        If Not Cells(i, 7).Value = "" Then
        MsgBox "modification"
    
        Else
        MsgBox "No modification"
        
        End If
        
    Else
    MsgBox "try again"
    
    End If
        
    Next i
    
    End Sub
    any help is greatly appreciated.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Your data may not be contiguous
    Try
    [VBA]
    intRowCount = Range("A" & rows.count).end(xlup).row -1
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Aug 2011
    Posts
    87
    Location
    without knowing exactly what you want to get, try this way
    [vba]Sub ds()

    Dim i As Integer
    Dim intRowCount As Integer

    With ActiveSheet
    intRowCount = .Range("A2").CurrentRegion.Rows.Count - 1
    For i = 2 To intRowCount

    If Not .Cells(i, 1).Value = "" Then
    .TextBox1.Value = .Cells(i, 1).Value
    .TextBox2.Value = .Cells(i, 2).Value
    .TextBox3.Value = .Cells(i, 3).Value
    .TextBox4.Value = .Cells(i, 4).Value

    If Not .Cells(i, 7).Value = "" Then
    MsgBox "modification"

    Else
    MsgBox "No modification"

    End If

    Else
    MsgBox "try again"

    End If

    Next i
    End With
    End Sub
    [/vba]
    Regards
    Osvaldo

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    A couple of observations, if I may:
    1. It would be helpful is you were specific about how the code fails. Do you get an error? If so, what and where? Or does it not do what you want? If so, in what way is it incorrect?
    2. Do not use Integers as row counter variables. Use Long instead. Integers can only go up to 32,767 and there are a lot more rows than that in a worksheet.
    Be as you wish to seem

  5. #5
    Thank you all for kind help.

Posting Permissions

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