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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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,215,029
Messages
6,122,757
Members
449,094
Latest member
dsharae57

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