excel vba

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

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Excel - VBA

Excel - VBA

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

Rotating Text in an Excel 2010 Worksheet

Maybe you want to draw attention to certain text or you just simply want to make your worksheet look more exciting!

One of the things you might consider is, rotating the text in a particular cell or set of cells.

1) Select a cell you would like to rotate
2) Click the ''Home'' tab in the Ribbon
3) Click ''orientation'' in the ''Alignment'' section
4) A pop up menu will appear with a few choices, if you want to decide yourself how many degrees to rotate the text, then click ''Format Cell Alignment.''

View all Excel hints and tips


Server loaded in 0.07 secs.