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

excel vba

ResolvedVersion 2003

Arabella has attended:
Access Introduction course
Access Intermediate course
Access Advanced course

Excel - VBA

I want to select a range in one workbook and if the totel of this range is greater than 0 then 1 appears in a selected cell in another workbook
I can do if the range is just one cell

THis is the code
If Range("Test1").Value > 0 Then
I have named the range test1

If the code reads
If Range("E10").Value > 0 Then
it works but I want to include the whole column

Any help would be welcome

Edited on Wed 25 Jun 2008, 10:20

RE: Excel - VBA

Hi Arabella

Thank you for your question

You need to create a module and copy the following code into it.

Sub ConditionalCopy()

Dim lngSum As Long

Application.Workbooks("Source").Activate

Sheets("Sheet1").Select

lngSum = Application.WorksheetFunction.Sum(Range("E3:E44"))

If lngSum > 0 Then

Application.Workbooks("target").Worksheets("sheet1").Range("A1").Value = 1

End If


End Sub



This code checks a range in a workbook called source and then copies 1 to a workbook called target if the sum of that range is greater then 0.

The key line of code is


 lngSum = Application.WorksheetFunction.Sum(Range("E3:E44"))


This takes the sum of the range of cells that you want to check using the worksheetfunction "sum" and asigned it to a variable called lngSum

This variable is then tested to see if its value is greater than 0 and if it is then the target workbook is opened and the value 1 assigned to range("a1") in Sheet1.

Obviously you will need to rename the workbooks and worksheets

Hope this helps, let me know if you need anything further

Regards

Stephen Williams
Microsoft Office Specialist

 

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:

Adding multiple rows in an Excel 2010 Worksheet

If you want to add more than one row to an Excel Worksheet, drag select the number or rows you want added to the spreadsheet.

Then right click on these selected rows, choose Insert from the menu, and the new rows will be added above the rows you first selected.

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.