VBA Code For Summing Of Selected Range Of Cells

May 12, 2011

I often find myself in the following situation - I will highlight a range of numbers to see what the sum is in the bottom right hand corner (the cells which I select areoften not all within the same column or are not consecutively listed under each other) .Depending on the circumstances I will then type out a SUM formula with the range to put that value somewhere in the spreadsheet - the problem being that I have to deselect the cells and then re-select these within the formula. When I have selected many numbers, it is not always easy to remember every number which I included.

As a way to remember the numbers, I format those cells in a certain colour before I do the SUM formula and would then include only those coloured cells in the formula. I would like to avoid this extra bit of work.

I am new to VBA but would like some form of code that allows me sum the contents of a selected range and paste that formula beneath the last value in the range - the range would have been selected before running the maco.

View 7 Replies


ADVERTISEMENT

Fill Range Of Cells With Text When Listbox Option Selected - Clear When Not Selected

Jul 25, 2014

I am using this code to hide or unhide rows of text on another sheet:

VB:
Sub ProcessSheet1ChangeOnCellJ7(ByVal Target As Range)

Dim sAddress As String
Dim sValue As String

'Get the address of the cell that changed without '$' signs
sAddress = Target.Address(False, False)

[Code]....

When the "Not Pursuing" list box option is selected (in cell "J7" or "J8" in Sheet 1) I need to add (or over-write) "Not Pursuing" to the range of cells in column "B" (in the "Tasks" sheet), but only for that particular Goal, meaning a limited range of cells in column "B". If the "Pursuing - Show All Tasks" option is selected for a Goal then these same cells need to be blank so that the appropriate person can enter their name into the cell.

The purpose for adding "Not Pursuing" automatically to these yellow highlighted cells is that it will facilitate filtering of tasks by individual in the "Tasks" sheet..

Again I have tried several times to upload a sample file and am unable to, which I know makes it more difficult to solve. (Is there some common mistake people make? I know it's an allowed format and is very small in file size....)

Code solution can be entered directly beneath:

VB:
If Target.Value = "Not Pursuing" Then
ActiveWorkbook.Sheets("Tasks").Rows("29:29").EntireRow.Hidden = False
ActiveWorkbook.Sheets("Tasks").Rows("30:48").EntireRow.Hidden = True

View 1 Replies View Related

VBA Code For Summing Up Cells On Multiple Worksheets

Jan 13, 2014

I have made a basic holiday planner, where each employee has one worksheet which shows 52 x 5 day weeks.

When an employee asks for holiday, I put a 1 in the corresponding day (cell). What I need to happen is that if 4 first aiders all ask for holiday on the the same date a warning User form loads up.

The names of the 4 worksheets are;

"Jason L 2014", "Sharon L 2014", "Alan B 2014" and "Chris M 2014".

The ranges for the 5 day weeks are

"B7:F7", "L7:P7", "V7:Z7"

"B10:F10", "L10:P10", "V10:Z10"

"B13:F13", "L13:P13", "V10:Z13"

"B16:F16", "L16:P16", "V16:Z16"

[Code] ........

The code should not run the User form until the sum of the same cells across the 4 worksheets = 4.

By this I mean if 3 of the first aiders book B7 off, the code searches the 4 worksheets and if the sum is 3 then nothing happens. However if the 4th and final first aider tries to book the same day off, when the code runs it totals 4 and the User form runs.

View 1 Replies View Related

Summing A Range With Errored Cells

Oct 12, 2006

I have to work on a sheet where the value in the cells is from a call to the GETPIVOTDATA() function. This may return #REF depending on the data. I need to sum a range of such cells treating a #REF value as zero. In another part of this sheet this is done by {=SUM(IF(ISERROR(D6:D17),0,D6:D17))} but as soon as I go to edit the formula the {} disappear and the formula wont work if I edit it. Putting the {} back in manually doesn't work either. How can I repeat what has been done before. (The sheet was originally created by consultants who have long gone and I have inherited it!)

View 2 Replies View Related

Going Down Range Summing Cells Until Number Is Reached?

Aug 7, 2012

Im struggling how to even start writing this code. What im trying to do is go down column S from row 2 down and sum up each cell until the sum = 700 then delete all the rows below that with some thing in them.

View 2 Replies View Related

Sort Selected Range Macro Code

Apr 23, 2008

I am copying and pasting from two different " timesheet" spreadsheets into a list. One of the timesheets has blank rows. I am attempting to sort the blank rows to the bottom after I paste the data, but every time I do, it either replaces the top row with "true" or deletes the headers,

Sub SortBlankRows()
Dim rngCurrent As Range
Dim c As Range
Dim inUsedRow As Integer
Set rngCurrent = Workbooks("Payroll Summary.xls").Worksheets(1).Range("A1:J1")
inUsedRow = Workbooks("Payroll Summary.xls").Worksheets(1).Range("D65536").End(xlUp).Row
rngCurrent = rngCurrent.Resize(inUsedRow)
rngCurrent.Select
Selection.Sort Key1:=Range("D1"), Order1:=xlAscending, Key2:=Range("F1") _
, Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
End Sub

View 3 Replies View Related

Change Event Code When 2 Cells Are Selected

Jul 15, 2014

Looking for a Private Sub Worksheet_Change(ByVal Target As Range) code to concatenate cell J, K, E and F cells when both J6 and K6 are selected. The cells start in J6 and K6. When both J6 and K6 are selected, I would like a VBA code to concatenate J6, K6, E6 and F6 in cell L6

(Here is the formula =IF(OR(J6="",K6=""),"",I6&" "&J6 &" "&K6&" - "&E6&" "&" "&F6 I have but looking for a VBA code to accomplish task).

When either J6 or K6 is selected, the code should not concatenate until both cells (J and K) are selected. I would also like a Clear Contents function to clear L6 (or L7, L100, L80 or L13) contents when either J or K cell is deleted. For example, if K value is deleted, the Clear Contents should clean J and L cells contents.

View 13 Replies View Related

Non-Continuous Range In Event Code: Show A UserForm When A Cell In 1 Of 31 Named Ranges Is Selected

Nov 7, 2006

I am using the following Selection_Change Event to show a UserForm when a cell in 1 of 31 named ranges is selected.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
Dim i As Long

For i = 1 To 31
If Not Intersect(Target, Range("StatPost" & i)) Is Nothing And Target.Value = "" Then
If Target.Offset(0, -8).Value = "" Or Target.Offset(0, -7).Value = "" Or Target.Offset(0, -6).Value = "" Or Target.Offset(0, -5).Value = "" Or Target.Offset(0, -3).Value = "" Or Target.Offset(0, -2).Value = "" Or Target.Offset(0, -1).Value = "" Then....................

View 3 Replies View Related

Define Range By Selected Cells

Jul 19, 2014

I am working on some code to copy data from one sheet to another, but I'm not sure if I'm going about defining the copy range correctly. I would like it so that the user can highlight a range of cells on the sheet between A3 and F last row (last row based on col C). However the user should be able to highlight rows in any column between A and F, and they could highly the records with just one column or multiple columns. It should take the row numbers of the highlighted range and use the that as the row number to extract the data from.

[Code] ........

Im currently getting runtime error 13 on 'CopyRange = Selection.Rows'

'CopyRange = Selection.Row' returns the single row number for the first cell in the selection, but i need the range of all the rows in the selection.

View 6 Replies View Related

Set VBA Range As Cells Selected By Cursor

Jun 5, 2009

The VBA code (in the code window) runs nicely on the range B10:B1000, but I'd prefer that it only run on a range I define by the cells that are currently highlighted/selected on the active sheet. How should the line of
Set SHOPS = Range("B10:B1000")

View 2 Replies View Related

Paste A Selected Range Of Cells

May 11, 2007

I think I have the comand to select a range of cells, but can not figure how to paste this selection later in the spreadsheet.

This is how the application works.

I have a spreadsheet that I am using as a template. The first 10 rows have to be repeated later in the same spreadsheet after I make a manual page break.

I the spreadsheet I am doing the following commands:
With xlApplication.ActiveSheet
xlPageBreakManual
.Rows(istartrow).Pagebreak = xlPageBreakManual
End With

View 9 Replies View Related

Excel 2010 :: VBA Code For Inserting Text In All Column B-cells Of Multiple Selected Rows

Jul 11, 2012

Software: Excel 2010, Windows 7

What is the VBA code for inserting text in all column B-cells of multiple selected rows?

I am creating a worksheet with a table containing various data related to orders of various materials (this is more or less data gathering from an older, paper-based 'system'). This table spans, columnwise, from A to D and expands downwards as more orders are added. The information in each column is: A=order number, B=type of material and C=material specs. and D=additional comments.

I've set it up so that the only thing I really have to do is to insert the type of material in the cells of column B, and the rest will sort itself out. Instead of having to insert a new row for each new entry and manually typing in the name of the material (these entries are often done in the midst of already existing data), I created several similar, macroed buttons for the different types of materials we use. These macros work by selecting the row of the currently active cell, inserting a new row and then add the name of the material in the column B-cell of this new row. What I am having trouble doing though, is to get the text-entry to work for a selection of multiple cells.

As an example, lets say that I would like to add 5 orders of "Grade A Steel" in the middle of the table - in the row above row 8. With the macro I currently have I can select cell B5, click the macro, and a new row will be inserted with "Grade A Steel" in column B of this new row. This action could be performed 5 times over, but would be easier if I could just mark a range of 5 cells, say B8:B12, click the macro and get the text/data inserted the column B-cells of all 5 of the new rows. So far I've been able to create a macro that inserts multiple new rows, but I've only been successful in filling the column B-cell in the first row leaving the 4 below empty.

View 8 Replies View Related

Change Color Cells In Range Selected?

Aug 28, 2013

[URL] and how I could modify the conditional formatting/vba to return the same effect but for a selected range, not just a cell?

View 2 Replies View Related

How Do I Total Selected Data From A Range Of Cells?

Nov 22, 2009

On worksheet 1 I have Column A with a list of names, which we shall call John, Paul, George and Ringo, listed randomly within 100 cells (A1 - A100).
I have Cells B1 - J100 with 3 options in each cell; Blank, C and NYC.

I need a list on worksheet 2 for each individual person showing;

(1) total number of cells marked C
(2) total number of cells marked C & NYC combined.

View 14 Replies View Related

Macro Leaves All The Cells In The Range Selected

Jan 20, 2006

I have a worksheet with ever expanding data - rows at the bottom of the data
are continually added. I have a simple macro that sorts all of the data
according to preset parameters and selects the next blank cell in column A,
ready for more data:

Sub Macro5()
Range("SortRange").Select
Selection.Sort Key1:=Range("SortRange"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom
Do Until ActiveCell.Value = IsEmpty(True)
ActiveCell.Offset(1, 0).Activate
Loop
End Sub

When running the Macro, this leaves all of the cells in the range 'selected'
(ie; coloured-over). What do I need to add to the Macro to just select the
cell in Column A and remove the highlighting from all the other cells?

View 9 Replies View Related

Use Range Of Selected Cells As Relative Reference

Mar 8, 2013

I have a data that is split into multiple cells and needs to concatenated. Unfortunately, the number of columns wherein lies the data varies throughout the workbook. As such, I wanted to select a range of cells, define this range as the reference point for the macro, run the macro, then move on (selecting a different number of columns on the next try).

For example, I have this:

A
B
C
D
E

1

No
Not Very Far

[Code] .....

I want to select cells A1:B1, run a macro concatenated the two columns, then select cells C1:E and run the same macro to get this:

A
B

1
No
Not Very Far

[Code] ........

So far, I have this:

Code:
ActiveCell.Columns("A:A").EntireColumn.Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveCell.Offset(5, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[1],RC[2])" '

View 9 Replies View Related

Macro To Add Formula In Selected Range Of Cells

Apr 26, 2013

I have a spread sheet with large number of data, problem is all are in various currency so rather than typing =#####.##/a1 in every cell to get the GBP amount (a1 where my exchange rate is linked) I thought if there is macro can do this job for rme.

So what i need is macro which once run enter the formula after the numbers already in the cell in selected or given range.

View 1 Replies View Related

Matching Cell Content Against Selected Cells - Not Range?

May 2, 2013

I'm trying to use the below formula to to return "true" when text in cell (M2) matches text in selected cells on same row (A2, E2, and G2)

However, all formulas I found online that serve this purpose deal with cell range only, not predetermined cells with exclusions.

Formula:

=IF(ISNUMBER(MATCH(M2,A2:G2,0),TRUE,FALSE) (This will match all cells between A2 and G2 against M2)

reforming this formula to match selected cells only in-between that range (A2, E2 and G2)?

View 7 Replies View Related

VBA For Fill Zero For Empty Cells In Selected Range Using Mouse

Feb 13, 2013

I require a VBA code to fill Zero for empty cell in seceleted Range. Range will be select by Mouse.

I try following Code.

But It will not sucessed.

HTML Code:
Sub Zero()
Dim ws As Worksheet
Dim Specifiedrange As Range
Dim Rng As Range

[Code]....

View 5 Replies View Related

Changing Color Of Selected Range Of Cells Using Macro

Jun 17, 2013

I'm trying to create a macro that will change the color of the cells I've selected to green. My selection will vary depending on what cells I'm trying to color green (not a fixed range). My current code only changes one cell of my selected range:

Sub IN_PCA()
'
' IN_PCA Macro
'
'
ActiveCell.Select
Range("M243").Activate
With Selection.Interior

[Code] .......

I've tried using "ActiveRange" in lieu of "ActiveCell" as well as other commands that would seem to be correct but have failed.

View 3 Replies View Related

Set Range From Selected Cells/Range

Sep 16, 2009

I have a macro which I manually have to change the range in order to run the macro, e.g. Set rngData = Range("B4:I12")

rather than having to change the range for each macro, I was wondering if I could run the macro for the highlighted area. I have tried this, but doesn't seem to work.

Set rngData = Range. CurrentRegion.Select

View 2 Replies View Related

VBA Find Function - Search Through Selected Range Of Cells For Key Letters

Jan 6, 2014

I am trying to code a macro that will search through a selected range of cells for key letters, for instance this cell may contain any combination of B, C, Te, Tc, RH, or LH. I would preferably like to search with capitalization being a factor but it is not a deal breaker. Below is a sample of what i have if the cell has a B, C it works for B but ignores the C i need it t o recognize both.

Code:
If InStr(1, ActiveCell.Text, "B") Then Range("O" + CStr(ActiveCell.Row)).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0

[Code] ........

View 9 Replies View Related

Fill Userform Textboxes From Select Cells In Selected Range

Mar 7, 2008

Arised from my earlier posting in Populate ComboBox With Specific Sheet Column Range. I have the following working code below, but am having trouble finding coding examples to select specific cells from the selected row (that was found by selecting a ComboBox value)and update TextBoxes with those individual values after the UserForm has been initialized (the bold "GREEN" comment in the code below). I have been able to find plenty of references to update TextBox values to Cells, but that doesn't do me much good in this application since the User needs to verify the old data in these cells before updating them using the UserForm TextBoxes.

I was toying around with several different variations of code (none of which worked properly), so I left it out for clarity of my working code. I'll post up this non-working code as needed, because I really wanted a fresh answer...not what I was trying to do. The attached file should be sufficient to see what's going on

Private Sub UserForm_Initialize()
With Sheets("SR Information")
.Range("A2", .Cells(Rows.Count, "A").End(xlUp)).Name = "MyRange"
End With
SRnumber.RowSource = "MyRange"
End Sub

Private Sub SRnumber_Change()
Dim ServiceRequestNumber As String
Dim c As Range
Dim rngG As Range
Sheets("SR Information").Select
With Selection
ServiceRequestNumber = SRnumber.Value
For Each c In Intersect(ActiveSheet.UsedRange, Columns("a"))
If c = ServiceRequestNumber Then..................

View 4 Replies View Related

Excel 2010 :: Auto Lock Selected Range Of Cells After Saving?

Jul 17, 2014

I have a log that is used to keep when items are due. I do not want my coworkers to delete items once they have been entered and saved. So the excel sheet I am trying to make has certain cells in a range that I want to autolock after saving. For example: the cell range is G3:J402. I enter Customer Name in Cell G3 and the Date the job was received in H3. Once i enter that information I want it locked once i save it. Then later on, my coworker completes the job and enters the date in I2. And again once she saves this she shouldn't be able to edit this information. Then again another day she comes and enters the date on I3 when the product has been shipped out.

While all of the above activity is going on, new customers are continuously being in added in G4, G5....

Also, if possible the date in the H range should be the date items are entered in G (this would be a nice added feature). I've included the file for review. I'm running Microsoft Excel 2010

[URL]

View 1 Replies View Related

Excel 2010 :: Auto Lock Selected Range Of Cells After Saving

Jul 17, 2014

I have a log that is used to keep when items are due. I do not want my coworkers to delete items once they have been entered and saved. So the excel sheet I am trying to make has certain cells in a range that I want to autolock after saving. For example: the cell range is G3:J402. I enter Customer Name in Cell G3 and the Date the job was received in H3. Once i enter that information I want it locked once i save it. Then later on, my coworker completes the job and enters the date in I2. And again once she saves this she shouldn't be able to edit this information. Then again another day she comes and enters the date on I3 when the product has been shipped out.

While all of the above activity is going on, new customers are continuously being in added in G4, G5....

Also, if possible the date in the H range should be the date items are entered in G (this would be a nice added feature). I've included the file for review. I'm running Microsoft Excel 2010.

I have tried hard to find other solutions with links at the following places but not exactly what I'm desiring:Auto lock cells after data entry when file saved...

Auto lock cells after data entered and SAVED.

Auto Lock Selected Range of Cells After Saving

I should also mention that most solutions either provide for locking/unlocking of all cells but not a selected range. Or they provide for locking/unlocking of a selected range but not for a specific sheet or not after you have saved the workbook.

This is unique in that I'd like it to autolock after i press the save button for a SPECIFIC number of cells. I just wanted to clarify as to not make others think that I haven't used the search function.

View 1 Replies View Related

Excel 2010 :: Copy Range Of Cells From One Sheet To Another Depending On Option Being Selected From Dropdown Box

Aug 13, 2012

Using macro's on Excel 2010. What I'm trying to do is create a macro that will copy a range of cells from one sheet to another depending on a option being selected from a drop down box. I've tried to use formulas but without success.
sheet 1 contains a list of approx 20 people with rows containing sales figures per week.

Is it possible to have a macro that will copy the rows to sheet2 depending on the dropdown? The drop down has already been setup with people's names

E.g.
if sheet 1, cell a1 (with data validation setup) dropdown contains "mr smith", copy sheet2 row A1:A9 to sheet 1 cell a2
or
if sheet 1, cell a1 dropdown contains "mr cooper", copy sheet2 row B1:B9 to sheet1 cell a2
etc... for each name in the dropdown

The idea is so that i select a dropdown and it copies the sales figures that match the dropdown name, if i then select another dropdown, the corresponding figures are copied to the same place.

View 3 Replies View Related

Copy A Selected Range Of Cells On Sheet One To A Range On Sheet Three

Aug 7, 2008

Hi. Does anyone know a formula to copy a selected range of cells on sheet one to a range on sheet three when a check box in checked. Ex. copy range a4:j4 on sheet one into a4:j4 on sheet three once the check box for on sheet one is checked?

View 9 Replies View Related

Code For Summing Between Workbooks

Jun 4, 2008

i am trying to write a macro that will allow me to, while two workbooks are open and one is defined as active i.e

in workbook 1 i want the cell A1 to be defined as the sum of cell A2 and A3 in workbook 2.

i have a code that lets me do it but the problem is that this code (that i recorded) only gives me specific workbook names to work from..

i dont know if i make much sense but i would like the macro to work on any 2 workbook that are open and perhaps having flexibilty to choose would be great here is my attempt

View 14 Replies View Related

Can Code Continue The Summing

May 16, 2009

*

A

B

C

D

E

F

1

DATA1

DATA2

SUM A+B

DATA3

DATA4

SUM D+E

2

The code I have here which sums row A and B in column C as shown in the table above And finish.


Sub Sum_Rows_1()

Dim LastRow As Long
Dim iRow As Long
Dim iCol As Integer
LastRow = 0

Is it possible code continue the summing up of row D and E in column F?

View 9 Replies View Related

VBA Code - Summing Groups Of Numbers

Jul 17, 2014

Product Group Arg.Braz.Mex.Peru
Red paint Paint5324
Blue paintPaint5684
WallpaperWallpaper6585
LampsFurniture 4631
ChairsFurniture 1645
Green paintPaint1356
SofasFurniture 3358

SUM(Paint,Argentina)SUM(Paint,Brazil)SUM(Paint,Mexico)SUM(Paint,Peru)
SUM(Wallpaper,Argentina)SUM(Wallpaper,Brazil)SUM(Wallpaper,Mexico)SUM(Wallpaper,Peru)
SUM(Furniture,Argentina)SUM(Furniture,Brazil)SUM(Furniture,Mexico)SUM(Furniture,Peru)

I am trying to work out VBA code or another way in Excel to find a solution for this problem - I need to be able to sum up the values that I have posted below - so for SUM(Paint,Argentina), this would be the sum of the red paint, blue paint and green paint values under the Argentina heading, that are all categorised into the 'Paint' group. The same follows for all the other categories. I was trying to use 'Defined Names' to group the categories together, and so would then do =Sum(Paint). However this was not allowing me to sum by each country, and the 'Create from Selection' naming tool was not naming all of the values for Paint (blue paint, red paint, etc.) under the paint category.

This is an incredibly simplified version of the data I am actually dealing with - I am doing this for 70 country columns and 250 rows of product categories.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved