98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Excel - VBA
Excel - VBA
Resolved · 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
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 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
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Rotating Text in an Excel 2010 WorksheetMaybe you want to draw attention to certain text or you just simply want to make your worksheet look more exciting! |