Hi,
I need to test a value in column B, and if it is less than 30, offset (0,2) and apply a number format to the value in column d. Then test the next B, and so on. I'm using Excel 2013. Thanks.
Hi,
I need to test a value in column B, and if it is less than 30, offset (0,2) and apply a number format to the value in column d. Then test the next B, and so on. I'm using Excel 2013. Thanks.
Hi, welcome to the forum
Have you looked at using Conditional Formatting for this?
1. highlight the range you want to apply the conditional formatting to (the range in column D)
2. on the home tab, styles, select CF
3. select new rule, select use formula
4. enter =A2<30 format as required
1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
2. If your question is resolved, mark it SOLVED using the thread tools
3. Click on the star if you think someone helped you
Regards
Ford
No, because I need to automate this for many worksheets on a regular basis. I'm thinking along these lines, but I'm not defining something correctly:
#Dim b As Range
For Each b In ActiveSheet.UsedRange
If b < 30 Then Offset(0, 2).NumberFormat = "?0.0""%*"""
Next b
#
Hi SGW, maybe this?
![]()
Sub checkb() Dim ws As Worksheet 'to set worksheet Dim lr As Long 'to find last used row in column B (assuming you want to check only cells with data Dim i As Long Set ws = Worksheets("Sheet1") 'change Sheet1 to the name of the sheet you are checking. lr = ws.Range("B" & Rows.Count).End(xlUp).Row For i = 1 To lr 'change 1 to the first row of data you wish to check If ws.Range("B" & i).Value < 30 Then ws.Range("D" & i).NumberFormat = "$#,##0.00" Next i End Sub
Please help by:
Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know
There are 10 kinds of people in this world... those who understand binary, and those who don't.
This looks good, but it has to work across sheets, so I have to set active sheet..I'll fool with this and see, thanks
sgw your code would check every used cell on the active sheet, did you look at the code I posted?
SGW across ALL sheets?
Yes, Arkadi, across all worksheets in the workbook. I haven't had a chance to try your code yet, it looks promising.
You can replace the "set ws = " line with set ws = activesheet, so you can activate the sheet you want, call macro, and activate next sheet, etc
![]()
Sub checkb() Dim ws As Worksheet 'to set worksheet Dim lr As Long 'to find last used row in column B (assuming you want to check only cells with data Dim i As Long For Each ws In ActiveWorkbook.Worksheets ws.Activate MsgBox ws.Name lr = ws.Range("B" & Rows.Count).End(xlUp).Row For i = 1 To lr 'change 1 to the first row of data you wish to check If ws.Range("B" & i).Value < 30 Then ws.Range("D" & i).NumberFormat = "$#,##0.00" Next i Next ws End Sub
Hi Arkadi,
Something's not working through correctly, does not step through each row on the active sheet. Thanks--I'll spend some more time with this.
Works on my end, but it only works through rows where b is not blank.
Let me know if and when I can help more![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks