Results 1 to 6 of 6

Thread: [RESOLVED] Set minimum value Column A (VBA)

  1. #1

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Resolved [RESOLVED] Set minimum value Column A (VBA)

    Hi,

    I have a lot of values in column A. A lot of them are below a value of 10, they all should have a minimum of 10. Anyone with a quick VBA solution?

    I tried:

    Code:
    Sub test()
        Dim c As Range
        Application.ScreenUpdating = False
        For Each c In ActiveSheet.UsedRange.Columns("A")
            If Trim(c.Value) > 0 And c.Value < 10 Then
                c.Value = 10
            End If
        Next c
        Application.ScreenUpdating = True
    End Sub
    It should skip empty cells if possible.

    Thanks in advance.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Set minimum value Column A (VBA)

    I tried:
    so what happened?
    wrong result?
    error?
    nothing?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Set minimum value Column A (VBA)

    Bit stupid not the tell you that. Sorry.

    "Types Mismatched"

    Code:
    Sub test()
        Dim c As Range
        Application.ScreenUpdating = False
        For Each c In ActiveSheet.UsedRange.Columns("A")
            If Not IsEmpty(c.Value) Then
                If c.Value < 10 Then
                    c.Value = 10
                End If
            End If
        Next c
        Application.ScreenUpdating = True
    End Sub


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  4. #4

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Set minimum value Column A (VBA)

    Was doing dishes and figured it out. It should be ...Range("A:A") instead of columns("A").
    The code is show however. Any suggestions?


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  5. #5
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Set minimum value Column A (VBA)

    Try this
    Code:
    Sub test()
        For j = 1 To 10 ' replace 10 with the number of last row
            If Trim$(Cells(j, 1)) <> vbNullString Then ' it is not empty
                If Val(Cells(j, 1)) < 10 Then
                    Cells(j, 1) = 10
                End If
            End If
        Next
    End Sub
    I don't know how to enumerate up to last row in a column, so i hard coded as 10, you should change it.



  6. #6

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Set minimum value Column A (VBA)

    That one is great m8. Simply add:
    For j = 1 to activesheet.usedrange.rows.count

    Thanks.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

Posting Permissions

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



Click Here to Expand Forum to Full Width