If Then Function in VBA Loop

Lauren123

New Member
Joined
Mar 16, 2018
Messages
28
Hello! I have the next code and is working but i would like to make it a loop, for every single cell there is with information.

Sub Internet()


If Sheets("Draft").Range("G7").Value2 = "INT1" Then
Sheets("U-Detail").Range("R11").Value2 = Range("'GL Accounts'!B1").Value2 & Sheets("Draft").Range("D7").Value2
Else
Sheets("U-Detail").Range("R11").ClearContents
End If


End Sub

On Draft.G7 sometimes it may be more values below and i would like to do the same until the last row.


If anybody could help i would be really grateful!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Where do you want to put the other values? will it be R11, then R12 etc?
 
Upvote 0
Maybe
Code:
Sub Internet()

Dim Cl As Range
Dim Rw As Long

Rw = 11
With Sheets("Draft")
   For Each Cl In .Range("G7", .Range("G" & Rows.Count).End(xlUp))
      If Cl.Value = "INT1" Then
         Sheets("U-Detail").Range("R" & Rw).Value = Range("'GL Accounts'!B1").Value & Cl.Offset(, -3).Value
         Rw = Rw + 1
      Else
         Sheets("U-Detail").Range("R11").ClearContents
      End If
   Next Cl
End With


End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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