vba if statements
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

replyReply Tue 20 Sep 2011, 12:10Delegate Christina said...

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

For upcoming training course dates see: Pricing & availability

replyReply Mon 26 Sep 2011, 15:25Delegate Christina said...

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

replyReply Tue 27 Sep 2011, 15:11Trainer Simon said...

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

 

Please browse our web site to find out more about
advanced excel course + london and other Microsoft training courses.

Excel tip:

Activating the formula bar with the keyboard in Excel 2010

The formula bar in Excel 2010 contains a number of different formulas. However, it is time consuming to open the formula bar every time and insert the formula using the mouse. Instead, you can activate the formula bar with the keyboard. Simply press the F2 button on the keyboard then the information in the cell will expand allowing you to edit the information in the cell.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard