Loop a simple if then statement with offset

Hardhat

New Member
Joined
Jul 28, 2017
Messages
23
I have two tables. I need information on one table transferred and converted to the second table. The IF Then statement is easy. But I do not want to have to write it out 700 times. I can not seem to figure out where to place the loops and offset to do what i am looking for. Below is the If Then statement and an explanation of what I am trying to do.

If Sheets(1).Range("F7").Value = 8 Then ' I need this to loop through Range (F7:S7)"

Sheets(3).Range("B5").Value = Sheets(1).Range("A7").Value 'this value to be place in Range (B5:O5) with Range 7 not changing

Else

Sheets(3).Range("B5").Value = "" 'this value to be place in Range (B5:O5)

'Then all the numbers to offset 1 down and repeat 55 times





End if


Please help I am a beginner, an my head is spinning. I am sure when I see the code I will fell like a fool for not figuring it out on my own.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hardhat,

You might consider the following...

Code:
Sub AnotherLoop_1062191()
Dim r As Long, c As Long, i As Long, j As Long
j = 0
For r = 7 To 62
    i = 0
    For c = 6 To 19
        If Sheets(1).Cells(r, c).Value = 8 Then ' I need this to loop through Range (F7:S7)"
            Sheets(3).Cells(5 + j, 2 + i).Value = Sheets(1).Cells(r, 1).Value 'this value to be place in Range (B5:O5) with Range 7 not changing
        Else
            Sheets(3).Cells(5 + j, 2 + i).Value = "" 'this value to be place in Range (B5:O5)
        'Then all the numbers to offset 1 down and repeat 55 times
        End If
        i = i + 1
    Next c
    j = j + 1
Next r
End Sub

Please note the code is untested.

Cheers,

tonyyy
 
Last edited:
Upvote 0
Tonyy,

Thank you So much. This works like a charm. This was way out side my skill level. Just proves what a beginner i am and how much more I will need to learn. Thank you again for your help.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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