|
-
May 12th, 2013, 02:22 AM
#1
Thread Starter
PowerPoster
[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.
-
May 12th, 2013, 06:50 AM
#2
Re: Set minimum value Column A (VBA)
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
-
May 12th, 2013, 06:57 AM
#3
Thread Starter
PowerPoster
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
-
May 12th, 2013, 07:05 AM
#4
Thread Starter
PowerPoster
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?
-
May 12th, 2013, 07:12 AM
#5
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.
-
May 12th, 2013, 07:21 AM
#6
Thread Starter
PowerPoster
Re: Set minimum value Column A (VBA)
That one is great m8. Simply add:
For j = 1 to activesheet.usedrange.rows.count
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|