mardi 6 janvier 2015

Excel Macro - Basic Looping of If Statements

I searched through the stacks but wasn't able to find a question similar to mine. So here's my question (I'm new so apologies for this basic question!). I want to write a simple macro that evaluates cell B2. If B2 has a value, I want the macro to paste a value from another worksheet (let's say: worksheet2, cell A1, which says "Award4455") into cell C2; if B2 is blank, I want the macro to leave C2 blank. Then I want to evaluate B3 using the same condition (filling or not filling C3, depending on whether B3 has a value or is blank). I want the formula to loop through 7 rows (B2:B8), filling (or not filling) the correspnding cells in column C.


Here's what I'm trying (unsuccessfully - I keep getting various error messages):


For i = 2 To 8


Dim Award As String


Award = Sheets("Sheet2").Range("A1").Value


If Len(Range(i, "B")) = 0 Then Range(i, "C") = Award


End If


Next i


End Sub


Aucun commentaire:

Enregistrer un commentaire