Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

vba if statements

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » VBA IF Statements & Looping

VBA IF Statements & Looping

ResolvedVersion 2003

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

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Use the SUBTOTAL function in Excel

You can create subtotals in your spreadsheet using the SUBTOTAL function, which looks like this:

=SUBTOTAL(9,cell:cell)

9 represents the function being used (SUM), followed by the range of cells the function is operating on.

The neat thing about using the Subtotal function is that if you have used it several times in the same column or row, clicking on the AutoSum button at the end of the column or row will make Excel add only the results of cells containing the Subtotal function in that column or row.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.