Christina has attended:
Excel Advanced course
Excel VBA Intro Intermediate course
VBA IF Statements & Looping
Hi there,
I wonder if you can help me, I would like the below bit of code to look at a particular cell, and if the value is true then perform the code, and move to the next row, but also if the value is false then move to the next cell and loop the code
Dim JnlDesc As Long
If ActiveSheet.Range("A3").Cells(IntRowCount, 10).Value = ("Journal") Then
JnlDesc = ""
Range("R3").Select
JnlDesc = ActiveCell.Text
Range("S3").Select
JnlDesc = ActiveCell.Text & " " & JnlDesc
ActiveCell.Text = JnlDesc
I hope I have not confused you! I am pretty confused myself!
Thank you
RE: VBA IF Statements & Looping
Hi there,
Please can someone help me. I am trying to write a VBA code that will loop and test on each line until the data has ended that says:
If J3 = "Journal", then concatenate cell R3 & S3, in Cell S3, then move to the if not then move to the next cell down and use the same If statement.
Please can you help me.
Thank you
RE: VBA IF Statements & Looping
Hi Christina,
Thank you for your question.
The following code concatenates cells R3 and S3 into T3, if cell J3 contains the word "Journal". If J3 doesn't contain the word "Journal" then it leaves the cells blank.
Hope this helps.
Sub TestThis()
Dim x As String
Dim y As String
Range("r3").Select
If Sheets("Sheet2").Range("J3").Value = "Journal" Then
Do Until ActiveCell = ""
x = ActiveCell.Value
ActiveCell.Offset(0, 1).Select
y = ActiveCell.Value
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = x & " " & y
ActiveCell.Offset(1, -2).Select
Loop
Else
Exit Sub
End If
Columns("T").AutoFit
End Sub
Regards
Simon