Automatically Format Range Based On Specific Cell

Aug 19, 2008

I am looking for VB code that will format a range of cells from a number format to a percentage format based on a reference cell. The reference cell is a drop down created from a list validation.

For example: If the reference cell (cell A1) =1 then cell range B2:C4 would be a number format. If A1 = 2 then cell range B2:C4 would be a percentage format.

I have searched for hours trying to find a relevant thread; I know they are out there, maybe I just wasn't typing in the correct search words.

View 5 Replies


Automatically Format Range Based On Formula Result Of Cells

May 16, 2009

The following code works perfect but the "change" event is only triggered when working directly on intersect range. Tried using the "calculation" event but could not figure it out. This is what I want:

1) To replace the code provided below using the calculation event
2) To only trigger the event for the row(s) where the new value was generated, not for the whole "For Each" statement
3) To use one single code for all worksheets, instead of copying the code in every working worksheet on the workbook, if feasible
4) And I would like a "second alternative", where the user of the workbook can click on a button and trigger the event on every row on the workbook that has a non empty cell within the intersect range, assuming that the intersect range column is the same for all worksheets

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, d As Range, fc As Long, bc As Long, bf As Boolean
Set d = Intersect(Range("I:I"), Target)
If d Is Nothing Then Exit Sub
For Each c In d
Select Case UCase(c)
Case "C"
fc = 1: fb = True: bc = 4
Case "O"
fc = 2: fb = True: bc = 3
Case "D"
fc = 2: fb = True: bc = 46
Case "G"
fc = 2: fb = True: bc = 5..................

View 4 Replies View Related

Entering Specific Text Into Cell Based On Its Format

Apr 13, 2013

I'm trying to make a schedule for some of my employees (300 to be exact) and I was trying to work out a way of speeding things up a bit. I've made plenty of pretty complex equations for working with the task but the solution for what I would like to do now alludes me.

Here's the challenge: I have a sheet where I would like to insert employees within row 4 and then have their shifts shown visually in the column below that, and have the hours they work put into a merged cell (or something similar), like what can be seen in the blue cell under "Employee 1" (C6). What I would like to do is just have something like a VBA detect that a series of cells is merged (red cells) and insert the corresponding time, located within B5:B33, into that cell (with same format as the blue cell). Also, above the employee's name I could put a button to run something like a macro to run the program for the corresponding employee directly under that button.

Essentially I want to merge a series of cells, hit a button, and have excel locate and input the correct times within that merged cell.

View 1 Replies View Related

Conditional Number Format Based On The Value Of A Specific Cell

May 9, 2009

I have a large spreadsheet which includes many rows whose number format needs to change depending on the value of a specific cell.

So for example:

If cell B20 has value "A", cells Q20:AG20 should display as 1,234
If cell B20 has value "B", cells Q20:AG20 should display as 5.6%
If cell B20 has value "C", cells Q20:AG20 should display as 7.89

As conditional formatting does not seem to include a number format option I've worked out that I need some sort of macro to change these settings for me, either automatically whenever the value of B20 changes or, more likely, when I manually choose to run the macro.

View 9 Replies View Related

Automatically Clear Range Based On Cell Criteria

Jan 9, 2007

I have the following Worksheet Change Event in my worksheet. The contents of range rng are not cleared.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range

rng = Range("F" & Target.Row & ":M" & Target.Row)

If Not Intersect(Target, Range("N5:N1000")) Is Nothing Then

If Target.Cells.Count = 1 Then

If Target.Value = "Yes" Then

Application.EnableEvents = False


Application.EnableEvents = True

End If

End If

End If
End Sub

View 9 Replies View Related

Using Conditional Formatting To Format Range Based On One Cell

May 20, 2009

I am working with the Conditional Formatting, which is fine for one cell. Here is what I am trying to do: IF cell in $A1 = 1 then bold $B2:$M2 and apply solid line border to top of cell ranges. I have tried conditional formatting but it only formats the cells in column A. And I can't seem to find a BOLD statement for the cell formulas.

View 2 Replies View Related

Format Color For Range Of Cells Based On Cell Value

Jul 1, 2008

I have been tasked with creating a Macro in order to help speed up a rather simple set of steps that are taken to format a spreadsheet each day. The last step, however, is not so simple. I would like to add a statement to the macro code that does that following:

Based on the value of a specific cell, color the cell and all corresponding cells within the same row (from colums A to AA) yellow. Essentially, cells in column D may have a the value "No Allocation", and if they do, I will need to format that cell yellow as well as all the cells within the same row for the colume range A to AA.

View 9 Replies View Related

VBA - Format Range Font Based On Value In A Reference Cell

Jul 3, 2009

I am preparing a model for a client that runs excel 2003. I need to change the format of a range based on the value in a cell (reference cell) that is outside the range to be reformatted.

Reference cell is a named cell with the value calculated with a Match() function, the only possible values are (1, 2, 3).

I need the VBA code to retrieve the reference cell value and apply one of three formats to the range. I believe the code for that part is something like:

Private Sub Format_Font()
Set vrange = Range("d63:r63")
Set refrange = Names("ind_agentfee").RefersTo
Set refrange = Mid(refrange, 2)
On Error Resume Next
If refrange = 1 Then
With vrange.Font
.Style = "Comma"
.NumberFormat = "_(* #,##0.0_);_(* (#,##0.0);_(* ""-""??_);_(@_)"
If refrange = 2 Then
With vrange.Font
.Style = "Comma"
.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
.Style = "Percent"
End If
End Sub

I am having problems getting the proper opening statements and declarations correct and also get an "Else without Then" error with all combination's that I am attempting. I am sure that the code is mess now as I started with a recorded macro then modified it multiple times while researching the web.

View 9 Replies View Related

Conditional Format Based On A Text Range Within A Cell

Nov 11, 2009

conditional format formula that is based on a text range within a cell. In my case, I would like to compare the low and high range when inputted as a number followed by the quotation marks followed by space then hyphen, space then number and ending in quotation marks. The quotation mark is being used to represent inches.

Like this in cell D14: 0.2 - 2.2

I am using the following condition format formula which works for the strict case above.

HTML =OR(D16<LEFT($D$14,3)+0,D16>MID($D$14,8,3)+0)
However, there will be times when users using this spreadsheet may leave out the spaces on either side of the hyphen, or add more than one space between the number and hyphen. Also if additional digits are added, my formula above does not include all the digits in the results. I prefer to leave the quotation marks in...........

View 9 Replies View Related

Populate A Specific Range Of Cells Based On A Value Of Any Kind In A Header Cell

Sep 22, 2009

I need to populated a specific range of cells based on a value of any kind in a header cell. Attached is a sample of the end results. Please remember each header cells needs to determine what happens the range of cells below the header cells.

View 3 Replies View Related

Format Cell To Always Insert Specific Thing When Specific Name Is Typed?

Apr 4, 2013

Is there a way to format cells to where - when you type in a certain person's first name, it will insert something entirely different?

This has seemed to have happened on a computer at work.

In Excel, when I type in "Martha" then tab, or otherwise leave that cell, Martha changes to "Cool"

If I type in anyone elses name - it stays that name. But if I type in "Martha" .. it changes to "Cool" with the bullet and the word Cool.

View 6 Replies View Related

Conditional Format Color Of Cell Based On Values In Range Of Cells?

Oct 24, 2013

I would like to format the color of cell A1 on Sheet 1 based on true or false values from cell range A1:A10 on sheet 2. For instance:

1. If all cells on sheet 2 in range A1:A10 were false then cell A1 on sheet 1 would be red.

2. If some cells on sheet 2 in the range A1:A10 were false and some were true then cell A1 on sheet 1 would be yellow.

3. If all cells on sheet 2 in range A1:A10 were true then cell A1 on sheet 1 would be green.

View 5 Replies View Related

VBA Conditional Format Range Of Cells Based Upon Criteria In One Cell / Repeat For All Rows

Apr 3, 2014

Code is trying to

1. Where there is data in column B
2. Goto first row of data
2. If column J = "Closed"
3. then select Cells from column B to J in that row and colour these cells in red
4. If column J= "Open"
5. the select Celss from column B to J in that row and colour these cells in grey
4. Repeat for next row until you get to cell in column B where there is no data.

Recieve run time error 1004: Method 'RAnge of object_GLobal failed

Sub Colourclosed()
Dim LastRow As Long
Dim i As Long
LastRow = Range("B" & Rows.Count).End(xlUp).Row
For i = 8 To LastRow
If Range("J" & i).Value = "Closed" Then Range("B", "J" & i).Select
Selection.Interior.ColorIndex = 3


Note: I've managed to do it for one cell ie for Column B by replacing "If Range("J" & i).Value = "Closed" Then Range("B", "J" & i).Select with "If Range("J" & i).Value = "Closed" Then Range("B" & i).Select" This works but only colours in cell in column B, how do i do this so it colours range of cells

View 4 Replies View Related

Automatically Mirror Specific Range On Another Worksheet

May 13, 2009

Hello, what I would like to do is take a portion of a sheet..... So the cells I want to mirror are in the proposal sheet cells B32 x F51. And then mirror the exact duplicate copy to another sheet. The other sheet should have those same values at A20 X G39. What I am trying to do is have a sheet that has skus, prices, and so forth and then when I add,delete, merge, color, or do anything to the cell on the "proposal creation" sheet I want it to mirror only a specific cells to another sheet that is "salesman copy" that we will print to clients. So this way ont he proposal copy a salesman can insert rows or even change the color of the cells and then have it mirror exactly the same on the "salesman copy" which is what we will print for clients.

View 9 Replies View Related

Format A Range(A3) With Specific Value

Dec 28, 2009

I have a value that the user is suppose to type in the range(A3). The format is as follow: 20091227-I1 (yyyymd-Letter and No.) The letters are I and EK and after the letter a # from 1-10.
I want to create a macro, which reads the Range(A3). If the format is incorrect, then a MsgBox would display "Typing error. Please type the year, month, date, dash, letter (I or EK) and number."
I don't have a problem creating the message box. My problem is validating the Range(A3) with the specified format.

View 9 Replies View Related

Automatically Date & Time Stamp Changes To Specific Range

Jun 4, 2008

i need to put a date stamp when a change is made in b3:b31 into e3:e31 for each row also i need to put a date stamp into g3:g31 when a change is made in F3:f31 i try to use 1 "worksheet-change" and it is fine once i use 2 i get Ambiguous Name Detected errors

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("b3:b31"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 3).ClearContents
With .Offset(0, 3) ............

View 9 Replies View Related

When A Date Entered On A Specific Cell, Automatically Enter A Text In Other Cell

Jul 10, 2006

I have 6 Headings in excel named...

"A" in cell A1, B in B1, "C" in C1, "D" in D1, "E" in E1 and "F" in F1.

There are two projects.

Project 1 has phase A, D & F and Project 2 has phase A, B, C, D & E.

My Specification follows...

1). Take Prject 1 - Which starts from cell A2 I will keyin "A". When the phase comes to an end I will key in the end date of the phase. As soon as I key in the end date in cell A2 Letter D should automatically appear in the cell D2 and when Phase D comes to an end I will key in the end date in Cell D2 which should automatically keyin F in the cell F2. and is the same case for Project 2.

View 3 Replies View Related

For EACH Cell In Specific Range Meeting Specific Criteria - Call Sub

Jul 1, 2014

Looking to have a macro call a subroutine every time it finds a cell meeting specific criteria.

Code in plain english would look like this:

For EACH cell in range A1:BZ500 meeting the following criteria:

Cell value is a date


Cell's date is at least a week or more in the future


Cell background (Fill) = RGB color code: (R:191 G:191 B:191)

DO the following:

Call repeatingsub

View 11 Replies View Related

Automatically Format Cell Border

Dec 27, 2008

I am trying to Formal my Cell Border automatically.

Lets say i have cells


These are single cells running downwards only. I want to format this 6 cells into 1 box using (outside borders) formating. I need to repeat this for every 6 cells into 1box...and continue on and on. Im doing this process manually...But i got like 100,000 cells...

View 5 Replies View Related

SUM Of Values In 1 Range Based On Specific Criteria In Another Range

Jan 31, 2009

I am tracking total man hours of contractors in columns of different rates applicable. At present I have structured my worksheet with the different rates across and days going down. As I am invoiced for a period of work I will log the invoice ref number in a separate field. I would like to sum totals to report against $ Invoiced and $ Committed (i,e worked but not actually invoiced against yet).

Here is an example of what I am trying to achieve. The Actual showing sum mhrs * rate only for the mhrs entries with an invoice in corresponding Invoice Ref Column. The Committed producing sum of all mhrs * rate [which I am using =(SUM(D9:D37)*D7)] regardless of what is in invoice ref column.

This way I can hopefully track what we have been billed and also what we can expect to have to budget for to cover what has been worked but not billed against.

View 9 Replies View Related

Change Cell Format Based On Existing Currency Format

Jun 12, 2008

I would like to have a single button that changes a range of cells from the USD to EURO to perhaps CAD symbol. Can this operation be performed, such that if I start in dollars, and I click the button once, it shifts by range to EURO (not formulas...just symbol)...and then if I click the same button again, it goes to CAD, and then back to USD with a third click?

View 5 Replies View Related

How To Automatically Update Cell Format In Cells That Reference Another Cell

Feb 22, 2012

Cell C3 has "Joe"

Cell X44 is a VLOOKUP that retrieves "Joe"

Let's say Joe goes on vacation. The workbook user goes in and puts a blue fill in C3. Cell X44 would also need to change automatically.

What's needed to make this happen?

View 1 Replies View Related

Automatically Format Date Cell As General

Jan 8, 2007

I have a cell that is constantly being changed from a date to a number. Excel automatically formats the cell as a date when a date is entered but if I re-enter a number it leaves the format as a date.

Is there anyway to automatically change the format back to general if a date is not entered.

I had this bit of code obviously it dosent work.

If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("E8:E46")) Is Nothing Then
If IsDate(Target.Value) Then
Target.NumberFormat = "d/mm/yy;@"
Target.NumberFormat = "General"
End If
End If
Cancel = True

View 4 Replies View Related

Read Specific Cell From Many Excel Files Automatically?

Mar 11, 2014

Is there anyway to read a specific cell from many excel files automatically and add them to a new workbook?

I tried to link that specific cell to a new workbook manually but now I have a problem: If I change the name of any workbook that is linked to the new workbook, Excel can't update the new file name

View 7 Replies View Related

Format Specific Lines Within A Cell

Jul 7, 2009

I am trying to write a macro that given a selected range of cells goes in each cell and bolds the first 2 lines within the cell. An example of this would be if the cell contained:.............

View 2 Replies View Related

Set Date Format For Specific Cell In VBA

Jan 26, 2012

What I have done is create a macro in Excel and then opened up the VBA editor to make a lot of changes to the initial macro. I am reformatting a whole lot of separate spreadsheets over many workbooks.

Here is the code that is generating the error (Run-Time error '438', Object doesn't support this property or method):

Selection.Format = "long date"
With Selection
.Font.Size = 11
' .Format = LongDate
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With

As you can see, I first tried the ".Format = LongDate" and did put LongDate in "" which did not work, then I tried the "Selection.Format = ..." after the "Range" statement, and that did not work either. So you will actually know, I am trying to set the format for the cell "E2" to a Long Date format.

View 7 Replies View Related

Calendar To Allow The User To Select A Date And Automatically Put That In A Specific Cell

Jun 11, 2003

I have created a user form using the addins that come with excel to create a calendar that will allow the user to select a date and automatically put that in a specific cell. My system is office 2000.

The code is as follows:

Private Sub OK_Click()

Dim i As Integer
Dim myCell As Range

i = 0

For Each myCell In Selection
myCell.Value = Calendar1.Value + i
i = i + 1
Next myCell

Unload Me
End Sub

Now, I gave it to my boss who has xp, and I get the following VB error when she chooses a date and clicks on the ok button:

Method 'Value' of object 'ICalendar' Failed

View 9 Replies View Related

Automatically Name Sheets Based On Range & Unhide Them

Aug 20, 2008

I found this very nice code on this site that changes the names of my sheets based on the first sheet, works great. What I want though is to have the sheets be unhidden when their name changes from the generic name "sheet1" to whatever else we call it. Can this code be manipulated to do that? I want the sheets whose names do not change to stay hidden, the others to unhide.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim lCount As Long

If Target.Cells.Count > 1 Then Exit Sub

On Error Resume Next
If Not Intersect(Target, Range("A2:A11")) Is Nothing Then
For lCount = 2 To 11
If Sheets(lCount).Name <> Me.Name Then
Sheets(lCount).Name = Me.Cells(lCount, "A")
End If
Next lCount
End If

View 3 Replies View Related

Automatically Create Named Range Based On CheckBox

Jan 20, 2008

I am quite new on this forum.

I would like a dynamic range to be multiplied with 2. The Range is always start in cell H14 to P?

I have multi checkbox in column F,

So here is an eksampel: If checkbox in F4 is true then Range H4:P4, should by multiplied with 2 else if the chekbox is FALSE, then only multiply with 1.

I want to entry data in the Range H14:P? by this code

Private Sub Worksheet_Change(ByVal Target As Range)
'Do nothing if more than one cell is changed or content deleted
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub

View 9 Replies View Related

Format Range Based On Legend

Aug 22, 2008

I need a basic code that accomplishes the following:

1) The user can define a legend for which he can format the cells in that legend however he wishes

2) Cells elsewhere in the sheet that have the same value as that in the legend will format exactly how they are in the legend

3) Default if not in the legend

I found this code that is close...but apparently it relies on the user selecting the cells he wants to format according to the legend code needs an Intersect command or something like that.

Also im not sure if this code actually takes into consideration font+border+shading code would need to take those into consideration.

example of the desired output is attached! ....

View 3 Replies View Related

Copyrights 2005-15, All rights reserved