hep with Loop

B

Bre-x

Row = 4
JJ = 1
For Col = 7 To 35
JJ = JJ + 1
Sheets("Main").Cells(Row, Col).Value = "=IF(AK4=G3,E4,0)"
Next Col

How change the G3 to H3, I3, J4.......

Thank you all
 
C

Crazyhorse

Try this

With ThisWorkbook.Worksheets("Newtemp")
For rowCt = 1 To .UsedRange.Rows.Count
If Round(.Cells(rowCt, 6).Value, 2) <> 0 Then
deRow = 3
Do Until Trim(ThisWorkbook.Worksheets("Info").Cells(deRow,
255).Value) = _
(Trim(.Cells(rowCt, 1).Value) & " " & Trim(.Cells(rowCt,
9).Value)) _
Or Trim(ThisWorkbook.Worksheets("info").Cells(deRow,
255).Value) = ""
deRow = deRow + 1
Loop
ThisWorkbook.Worksheets("info").Cells(deRow, 255).Value = _
(Trim(.Cells(rowCt, 1).Value) & " " & Trim(.Cells(rowCt,
9).Value))

ThisWorkbook.Worksheets("info").Cells(deRow, 256).Value = _
ThisWorkbook.Worksheets("info").Cells(deRow, 256).Value + _
.Cells(rowCt, 6).Value
End If
Next rowCt
End With
 
B

Bernard Liengme

Sub dothis()
Row = 4
JJ = 1
mycode = 71
For Col = 7 To 10
JJ = JJ + 1
myform = "=IF(AK4=" & Chr(mycode) & "3,E4,0)"
mycode = mycode + 1
Sheets("Main").Cells(Row, Col).Value = myform
Next Col
End Sub

best wishes
 
C

Crazyhorse

try this

Sub test()

Row = 3
For Col = 7 To 35
'Column 6 is column F
Sheets("Main").Cells(Row, 6).Value = "=IF(AK & Row = G & Row,E4,0)"
Row = Row + 1
Next Col



End Sub
 
R

Rick Rothstein

Something like this maybe...

Row = 4
For Col = 7 To 35
Sheets("Main").Cells(Row, Col).Value = "=IF(AK4=" & _
Cells(3, Col).Address(0, 0) & ",E4,0)"
Next Col
 
B

Bre-x

Thank you all for you help

Bernard's function is the only one I could make it work.
but as soon as it reach AA Column it gives me an error
I have to change "For Col = 7 To 10" to "For Col = 7 To 35"

Row = 4
JJ = 1
mycode = 71
For Col = 7 To 35
JJ = JJ + 1
myform = "=IF(AK4=" & Chr(mycode) & "3,E4,0)"
mycode = mycode + 1
Sheets("Main").Cells(Row, Col).Value = myform
Next Col
 
B

Bre-x

Row = 4
For Col = 7 To 35
Sheets("Main").Cells(Row, Col).Value = "=IF(AK4=" & Cells(3,
Col).Address(0, 0) & ",E4,0)"
Next Col

Actually Rick's works very well

Thank you all!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top