vba if statements

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

VBA IF Statements & Looping

resolvedResolved · Urgent Priority · Version 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:

Change the Default Width of All Columns in Excel 2010

If you want to change the width of the columns in your Excel 2010 spreadsheet, making them either larger or smaller, here's how:

In the Cells group on the Home tab, click Format.

Hover over the section called Cell Size and a drop down list will appear, select Default Width from this list.

In the Standard Width dialog box, enter the size you want to set as the default width and click OK.

View all Excel hints and tips


Server loaded in 0.07 secs.