Applying Macro To Selected Range

Apr 3, 2014

I have a macro which sorts data within a cell. This is working perfectly fine but the only problem with this is that it works only for a single which is selected. How can I apply this macro to range of cells I select using a mouse.

View 3 Replies


ADVERTISEMENT

Applying Macro Code To A Range Of Cells

Dec 26, 2009

how can i do the following using VBA
making each cell in column A added to each cell in column B and the result will be in the column C
for example
c1=A1+B1
c2=A2+B2
c3=A3+B3
... etc

i know i can do that simply without vba code but I just want to use this method to implement more complex formulas .

View 9 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

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

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

Applying Date Range

May 18, 2009

To explain I have two sets of merged data. On one fixed column I have two different sets of peoples age

1 - by age grouip eg 25 - 34
2 - By birth year so 01/02/1983

I know that person who is born between 1975 and 1984 would fall into the age group 25 - 34

I want to convert all the birth years into age groups. Its a lot of data (30,000 rows +) in random order

Does anyone have any idea how I would set this up, as I really want to add "age group" to a pivot table I have.

View 6 Replies View Related

Create Macro To Run In Selected Cell For Defined Range?

Jan 11, 2013

I created a named range formula:

=TEXT(TODAY(),"m/d/yyyy")&" "&TEXT(NOW(),"h:mm AM/PM")

The goal of that formula was to return a Date/Time stamp that is fixed and doesn't change over time. The formula is intended to run in which ever cell that I select to enter it into. I named the formula:

=DS

What I am trying to do is create a macro that will run the formula using a hot key function. I want to be able to select a cell and hit CTRL D and have that above formula run in that cell. I have multiple sheets in my workbook and I need the macro to be able to run on any sheet in my workbook. Below is what I have:

Sub DateStamp()
'
' DateStamp Macro

[Code]....

I was trying to apply the macro to only a certain range of cells on any given sheet.

View 1 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

Looping Through A Range And Applying A Calculation

Feb 6, 2008

I have 10 ranges that if the value in a cell falls into one of those ranges, a calculation needs to occur. I think I need to use a macro which i have set up to run off a button click, with a do loop in it, but not sure how to get the loop to move down the range?

for example:

Cell Reference(s):

D
1 250
2 700

Range:

A B C
1 0 150 75
2 150.01 300 125
3 etc.. etc.. etc..

Formula:

=if(and(d1>a1,d1

View 9 Replies View Related

Applying Two Seperate % Discounts To A Range

Apr 4, 2008

Im using a commandbutton to apply a discount to a range of cells. I want to give the user two options based on either 18 months or 24 months.

So I was thinking somthing like, when the command button is used have a msg box asking them which term 18 or 24 than apply the discount to Range H25:H34.

I want to set the discount % to Range P20 for 18 months and P21 for 24 months.

View 9 Replies View Related

Applying Routine Over Unique Range

Jun 29, 2006

I was able to get my four conditional statements in VBA to work. This covers one complete row of data (week), but I need it to cover an entire year. Rather than cut and pasting 365 times (and some UGLY code at that), I have been trying to figure out how to add a loop or something to cover a range of different rows. Basically Columns B though V are good for row 21. Now every 14th row I need this routine to work for (B35:V35, B49:V49, etc) for 52 weeks. I was playing around with the idea of two for statements taht would count shifts (21 = 7 * 3) and weeks (52). Then step the rows at 14 and the columns at 1 (Rows = Rows + 14) for 52 iterations. I'm sure there is a better way to distribute this routine.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim changeRange As Range

Select Case Mid(Target.Address, 2, 1) 'Column Letter
Case "B"
Set changeRange = Range("B21")
Case "C"
Set changeRange = Range("C21")
Case "D"
Set changeRange = Range("D21")
Case "E"
Set changeRange = Range("E21")

View 9 Replies View Related

VBA Macro - Copying Entire Row From Selected Cell (within Pre-defined Range)

Jun 21, 2014

I am looking to run two separate macros. I have a project plan and I am looking to be able to select a button whereby on-click, a new row is created within a selected cell. However if the cell clicked is outside of a pre-determined range, then the task is automatically entered at the bottom of the plan. I would like for the copied row to go ABOVE the selected cell and have all of the same formatting as the row below (not the top - as is default in Excel).

The second is going to be very similar but will copy a task category (like a header item) and the first task (row) found below. It will also be copied from below and be inserted above the selected cell.Both macros will clear certain cells, whilst maintaining the contents of others, with formula contained. I.E. Columns C,D,E,H,I,J will be cleared.

View 2 Replies View Related

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

Counting Consecutives Values In A Range And Applying (yes / No) Result

Mar 3, 2014

I need to input a formula that will produce a "yes / no" result if a "0" value appears consecutively six or more times.

Using the date below (ranges A1:Q1, A2:Q2 and A3:Q3), I need cell R1 to read "yes", as there are 7 consecutive "0" values. Cells, R2 and R3, however, need to read "no" as there are less than six consecutive "0" values in rows 2 and 3 respectively.

A
B
C
D
E
F
G
H
I
J

[code].....

View 8 Replies View Related

Applying Macro To Entire Spreadsheet At Once

Feb 6, 2009

For simplicity, let's assume I have three columns, "Company," "Policy," and "Balance."

Example:
Company A Life $1
Company A Med $2
Company A Dent $3
Company A Disab $4
Company B Life $9
Company B Med $5
Company B Dent $7
Company B Disab $2

According to my post preview, the columns are running together, but I do have it arranged in three distinct columns. What I want to do is program a macro to do the following:

Every time the name of the company changes, I want Excel to insert two rows after the last of the group, and have a summation of the "Balance" column in the first inserted row.

This is what it should look like:

Company A Life $1
Company A Med $2
Company A Dent $3
Company A Disab $4
$10 <- (this should be directly under the $4, but I'm not good with forum languages)

Company B Life $9
Company B Med $5
Company B Dent $7
Company B Disab $2
$23 <- (same with this - should be directly under the $4)

View 3 Replies View Related

Applying Macro Code In Multiple Sheets?

May 23, 2013

i have a macro code but i don't know how to apply it to all sheets in the same workbook

my code is

VB:
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Range("D5:D100"), Target) Is Nothing Then
Target.Offset(0, 1).Value = Now() [code]....

View 1 Replies View Related

Excel 2007 :: Applying Conditional Formatting To A Dynamic Named Range?

Jul 10, 2012

I have an Excel 2007 Workbook which is refreshed by a Web Query. I have dynamic named range defined as "Manager" which I've confirmed is correctly identified. This range includes only one column and is formatted as text.

When I try to reference this range in my conditional formatting "refers to" formula, all cells are recognized as blank even though the range clearly contains many cells that are not. For example, there are 90 records containing the initials "PD". If I use the formula =Manager="PD" in my conditional formatting, nothing changes. If I change it to =Manager="" then ALL records are formatted, including those that are not blank.

Stranger still, if I enter the formula =COUNTIF(Manager,"PD") into and empty cell in my worksheet those 90 records are counted correctly. Which leads me to believe it isn't about the data. Conversely, =COUNTIF(Manager,"") returns the correct count of only cells that are, in fact, blank.

I've tried using the OFFSET formula defining my range in place of the name itself for my conditional format formula to no avail.

View 2 Replies View Related

Cannot Select And Pull Down Cells To Copy After Applying A Macro

Apr 23, 2014

I was messing around with some Macros, as an issue came up where clients were pasting over Data Validated cells (thus removing the validation). Somehow though, the feature where you can select a cell, then pull the active cell down through the column (and then can copy, fill series, etc)has become disabled. I deleted all the macros, and turned them off in the Trust Center, but when I click on a cell the box and plus sign still won't display for me to pull the cell down the column.

View 2 Replies View Related

Excel 2010 :: Macro For Applying Changes To Multiple Files

Aug 16, 2012

Excel 2010, Windows 7

I have a whole ton of *.dbf files (98 to be exact), that are from ArcGIS shapefiles. These date1_date2.dbf files have point names, and values, as shown below.

NAMERASTERVALU
Point 1-9999.00000000
Point 2-9999.00000000
Point 3-9999.00000000
Point 4-4.93072701
Point 5-8.90071201

I'm trying to figure out how to transpose each of the dbf files and save them as a text file (tab deliminated). My original plan involved saving them all as text files, then using a convoluted Unix script (I'm what you call a "dirty programmer") to transpose them and then combine them all into a single file. Since there are so many files (and I plan to do this in the future as well), I thought if I could at least automate the text file creation, I'd be ahead of the game. Even better would be a macro that will transpose the data for EACH file, then create a 99 (98 files + header row) row, 5 column text file. Creating the text files (1 text file for each dbf file) automatically .

All the *.dbf files will have exactly the same # rows/columns (2 columns, 6 rows)

This is what I've tried so far.
1)open one of the dbf files in Excel
2)record my marco (using the Personal Macro Workbook option - so it will be available in any workbook)
2a) transpose data (and paste it right below the original data so that the new data is in rows 7 and 8 of the same file)
2b) save as text file (tab deliminated)
2c) stop recording, and end up with this:

NAMERASTERVALU
Point 1-9999.00000000
Point 2-9999.00000000
Point 3-9999.00000000
Point 4-4.93072701
Point 5-8.90071201
NAMEPoint 1Point 2Point 3Point 4Point 5
RASTERVALU-9999.00000000-9999.00000000-9999.00000000-4.93072701-8.90071201

So now I want to apply the macro I just created to all open workbooks (after I bring in all the bdf files), but the macro isn't listed when I click the "view macros" button. All I want to do is apply the steps I recorded in the macro to all open workbooks.

View 6 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

Calculate Only Selected Range

Oct 5, 2009

I'm currently on Manual Calculation mode. I have formulas in cells A1 to A10 which has not been refreshed. Can I select only range A3 to A6 and recalculate only those cells?

View 5 Replies View Related

Expand Selected Range

Nov 15, 2009

I need help please. Using a macro, I have selected the range C7:C12. Now I need to keep this selection and expand it 18 columns to the right. This would give me a selection of C7:U12.

The original range changes at various times. Some times it might be C7: C452 etc.

I know it's easy, but I can get the code to keep the selection.

View 6 Replies View Related

Inserting Range Above Selected Row

Mar 8, 2012

I have a range (of 2 rows) that are set up as a header row and sub row. I want a macro to insert these above the active row (ie. where the user places the cursor), but when I select and copy the range in the macro, I don't know how to refer back to the 'active row' because that's not active anymore.

I'd also like the cursor then to be placed into one of the cells in the new row, ready for the user to start editing.

View 6 Replies View Related

Looping Through Selected Range

Jul 2, 2013

I am looping through a selected range. The code searches through column B and finds any data. If found, it returns the value to a different workbook to column B. When there is no more data, it goes to column C and does the same thing. My problem is, when there is no data in a column it returns a blank. How do i get rid of this blank???

View 1 Replies View Related

Count & Sum Of The Selected Range

Mar 16, 2007

Count & Sum is one of the most usefull function in the Excel,
I always used this, Is it possible in VBA to create such code that if I Select a range and click on Commandbutton1 automatically one msgbox display with the Count & Sum of the Range Item

eg. If Range A2 to A5 has a number like 50,10,20,10

here if the command button is click automatically one msgbox is display
which showing the

-Total Sum of the Seletced Range is 100 and Total Count is 4

View 9 Replies View Related

If Statement With Selected Range

Aug 10, 2007

I'm trying to create an if statement that have 2 criterias. Here's what I've created:

=IF(COUNT(F2:F4)=('2007Open'!H2:H4),COUNT('2007Open'!B2:B4)=8,'2007Open'!H2:H4)

This statement is returning the #VALUE error.

I guess what I'm trying to do with this statement is to count how many values are not equal to 2007Open!H2:H4 and meets another criteria of 8.

View 9 Replies View Related

Autofill Using A Selected Range

Jan 4, 2008

I am using the following code to Autofill a formula through a variable range:

Selection.AutoFill Destination:=Range(MyFormulaCell, TerminalCell), Type:=xlFillDefault

MyFormulaCell is the cell with the formula, and TermnialCell is a variable set on a count of rows. This is working great, and I can loop through this for the columns I need to copy just fine by incrementing values, but as I apply this to several sections, it's taking me up to a minute to run the macro. In this "I want it now" day and age, I'm sure my coworkers for whom I am making this will not be happy to wait that long.

Is there a way that I can incorporate a selected range into this method?

I'd like to set MyFormulaCell to:
Range(Selection, Selection.End(xlToRight)).Select
and then autofill the formula down the number of rows contained in TerminalCell.

View 9 Replies View Related

User Selected Range

Dec 3, 2008

I have a form that asks at what row the user wants to start with a selected range then how many rows to select. There will always be 21 columns selected with this range. I am still learning but it has to do with something on how I am setting the Start object. It is not being recognized.

Dim Row As Long
Dim Selection As Long
Dim Start As Range

Row = txtStartRow
Selection = txtHowMany
Set Start = Range("A" & txtStartRow).Select

Range(Start & ActiveCell.Offset(Selection, 20)).Select

View 9 Replies View Related

Delete Selected Range

Mar 17, 2009

My data is in one column as follows:
ABC
(BLANK)DEF (BLANK)(BLANK)
What I want to do is to delete the blank cells and count how many not-empty cells.

The following sub works fine if I put the active cell manually in A1. However, the first range select always give me the "1004" error. Why? I don't have any clue.

Range("a1:a5").Select
Do Until ActiveCell.Value = "stop"
Do Until IsEmpty(ActiveCell)

Selection.Offset(1, 0).Select
Loop
ActiveCell.Delete
Loop

View 9 Replies View Related

Chart Selected Range

Nov 29, 2006

I am trying to link data that has been entered into a inputbox with a range of cells.

My goal is to allow the user to answer: how many people sat the exam?

Therefore when a chart is automatically produced only the cells with the required data are selected.

So, my range is A2:C*

* being the user input.

View 4 Replies View Related







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