Macro to populate range of cells

royca

New Member
Joined
Jan 27, 2011
Messages
44
Hi Folks,

I have a range of cells that I would like to populate using a macro in the following way for example.

If A1 < 50 Then
E1 = A1 + 40
F1 = B1 + 20
G1 = C1 + 20
H1 = D1 - E1
Else If A1 >= 50 And A1 < 100 Then
E1 = A1 + 80
F1 = B1 + 40
G1 = C1 + 40
H1 = D1 - E1
.....

I apologize about the syntax. Anyway for some reason I can not wrap my head around the best way to do this for 30 rows of data. I suppose a loop of some variety but I couldn't find in my searches how to do that, something I figured would look something like this; Range("A[LoopCount]")

I imagine this is probably something basic but then so am I. Any suggestions are more than welcome.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I think the basic concept would be

Code:
Sub CheckA()
    Dim i As Long
    Dim LR As Long
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
    For i = 1 To LR
    
        If Range("A" & i).Value < 50 Then
            Range("E" & i).Value = Range("A" & i).Value + 20
            
        ElseIf Range("A" & i).Value >= 50 _
               And Range("A" & i).Value < 100 Then
            Range("E" & i).Value = Range("A" & i).Value + 80
            
        End If
        
    Next i
    
End Sub

I did not type all your requirements because based on the sample I thought you could fill in the rest
 
Upvote 0
Thanks FryGirl that is exactly what I was looking for, big help.

Should I use formulas? There are going to be 6 if statements per formula for 90 cells. A quick macro seems more efficient to me and easier to modify, but then what do I know. Insight?
 
Upvote 0
Thanks FryGirl that is exactly what I was looking for, big help.

Should I use formulas? There are going to be 6 if statements per formula for 90 cells. A quick macro seems more efficient to me and easier to modify, but then what do I know. Insight?

I think I am missing something here, I only see one level of nested if.

In E1

=IF(A1<50, A1+40, IF(A1<100,A1+80,""))

Edit: Oh wait, I get it you mean you will continue to increase in increments of 50 in the test yes? So <50, <100, <150, <200 etc etc
 
Upvote 0
I get it you mean you will continue to increase in increments of 50 in the test yes? So <50, <100, <150, <200 etc etc

That's right. I want to change cell colors and other things too eventually. Anyway I love this board you guys are all awesome with quick responses and suggestions.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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