Quick Coding Question

Desu Nota from Columbus

Well-known Member
Joined
Mar 17, 2011
Messages
556
Code:
Sub testing_2()
    Select Case Sheet1.Range("A1").Value
        Case Is < 0.85
            Rows("10:20").EntireRow.Hidden = True
        Case Else
            Rows("20:30").EntireRow.Hidden = True
    End Select
End Sub
This macro looks at A1 and then hides the rows based on the cases I created. I understand this, but now I want to apply a macro to a look at all values in column A.

How do I make a macro continue down column A until the first blank ? For instance, I want it to add cell B# and C# if A# < .85?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Example:

Code:
Sub Test()
    Dim LR As Long
    Dim r As Long
    With Sheet1
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        For r = 1 To LR
            Select Case .Range("A" & r).Value
                Case Is < 0.85
'                   Your code here
            End Select
        Next r
    End With
End Sub
 
Upvote 0
Example:

Code:
Sub Test()
    Dim LR As Long
    Dim r As Long
    With Sheet1
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        For r = 1 To LR
            Select Case .Range("A" & r).Value
                Case Is < 0.85
'                   Your code here
            End Select
        Next r
    End With
End Sub


Andrew,

Thanks for the help. If you could answer a few questions for me I would most appreciative.

1) For the Your code here: How do I refer to the actions I want to take place? For instance, if I want to say add B and C together and place result in D do I put:

Range("D").FormulaR1C1 = "=sum(RC[-2]:RC[-1])"


2) What is the logic behind the indents for each line of code?

3) And say I wanted multiple events to happen when the case is true, how would I add another action?
----> Range("F").Value = "yes "

Puts a yes in all cells that meet the case.
 
Last edited:
Upvote 0
It would be:

Rich (BB code):
Range("D" & r).FormulaR1C1 = "=sum(RC[-2]:RC[-1])"
Range("F" & r).Value = "yes "

Indenting just makes the code more readable. The indents are within each construct.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,849
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top