VBA Code - Changing Formatting Of Adjacent Cells At Varying Places

Jul 31, 2012

I have a macro that, at varying places, changes the formatting of adjacent cells. The formatting code is easy to generate via the macro recorder, but it's long - longer than the macro itself - and I'm using it a couple of times (due to if statements). That makes it difficult to read. It's usable, but looks ugly. I'd like to streamline its appearance.

Is there a way to do something like:

Code:
If range("F5").Value > 0 then
Activecell.Offset(1,0) format = blah
ElseIf Range("F5").Value = 0 then
Activecell.Offset(-1,0) format = blah
End If

The formatting I want is dark gray interior with a border box around it. The macro recorder generated this:

Code:
Sub test2()
'
' test2 Macro
'
'
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1

[Code] ............

View 3 Replies


ADVERTISEMENT

Changing The Decimal Places Without Rounding The Numbers

Mar 19, 2009

I was trying to decrease the decimal places of the data figures that I'm currently working on my report, however, it keeps rounding-up the decimal numbers. I wish to keep the original numbers and just decrease the decimal places.

For example:
The original figure is = 7260.12903225806
Upon decreasing the decimal figures to just 2, the result became = 7260.13

Is it possible for me to just have this result = 7260.12 instead of 7260.13?

I've tried using the TRUNC formula butit does not work if the 2nd decimal value is 0.

For example:
The original figure is = 227161.905808985
Upon applying the formula, the result became = 227161.9 instead of 227161.90

View 4 Replies View Related

Conditional Formatting Based On Top 10 Values In Adjacent Cells?

Jun 3, 2014

I have a matrix in excel to show % and $ for multiple columns - set up like this:

Rows Part 1 Part 2 Part 3
Criteria 1 % $ % $ % $
Criteria 2
Criteria 3

the $ columns are conditionally formatted to highlight the top 10 values on the matrix. is there a way to have the corresponding % cells also highlighted? The % and $ aren't both top 10, so the % would have to be highlighted based on the $ top 10 cells.

View 6 Replies View Related

Conditional Formatting Of Adjacent Cells From Dropdown List?

Jan 9, 2013

In one column I have a drop down list of a dozen different initials with conditional formatting on those cells. I would also like to conditionally format an adjacent text string column based on those initials, but don't want to set up a dozen rules on each cell, one by one. If I set up the top cell with the correct rules I cannot fill the formatting in because the formula is not updated on a row by row basis, but en bloc for the range.

View 3 Replies View Related

Conditional Formatting To Check If Adjacent Cells Are Empty?

Jul 18, 2014

I've got a list and I need to check if the adjacent cells for a column are empty or not, and if both are empty then format to a certain color. I have a solution but don't know how to implement it into a format fit for conditional formatting.

I have this in the new rule section of conditional formatting

=IF(AND(ISBLANK(OFFSET(I4,0,-1)),(ISBLANK(OFFSET(I4,0,1))),(ISBLANK(I4)=FALSE)),TRUE,FALSE)

If conditional formatting would allow it I would simply change I4 to the entire range, I am very much confused as to how to format this cell to work with conditional formatting. (I4 is the first cell in the list)

Something else is that if I change I4 to I5 or something then moves all the highlighted cells around, and to top it off the first few cells which should obviously be highlighted aren't, even though the rest of the cells which should be highlighted are.

View 7 Replies View Related

Excel 2007 :: Changing Number To Add Decimal Places

Jan 30, 2013

I am using Excel 2007 and importing a list of coordinates. The coordinates are in a text file and separated by commas, so I'm opening the file as a delimitted file. All of the coordinates import correctly except one. The value is supposed to 52530.6372, but Excel is automatically changing it to 52530.6371999999

If I manually type a "2" to replace the "1999999", it changes it back. If I type "3" it stays as a 3.

I added a round function to force it to round to 4 decimal places and that seemed to work until I then tried using the number with text commands. When I used an ampersand to insert the number into a text string, the additional decimal places are back, even with a round function!

View 1 Replies View Related

Variable Type Changing Number Of Decimal Places

May 14, 2014

Here's what I'm doing: I'm using a macro to assign a cell value to a variable then set another cell value to the variable instead of copy/paste (because even pasting values only was affecting other formulas in the file for some reason)

The problem: in using the macro, the number being 'copied' is acquiring a few extra decimal places IE 38334.61 is the original number and 38334.609375 is what I end up with. The numbers come from a CSV with only 2 decimal places and I checked by adding decimal places in the format so it's not a formatting/visible digits issue. Since the values are hour meter readings, the extra decimal places end up with very small values outside 0-24 hrs which messes with sorting and usage %. The values are so small all of them together in a month add up to a fraction of a cent but it's one of those things that bugs my OCD by not being right.

My VBA book explains the min/max capabilities, content type, memory bits but not fiddly details like this.

So my question is this: right now I'm declaring the clipboard-substitue variable as an single, is there a different one that would work better without adding anything? Criteria are: numeric, 6 digits before the decimal, 2 after, all positive values. (Ie 123456.12)

EDIT: fixed my senior moment.

View 6 Replies View Related

Conditional Formatting Date Cells Based On Entry In Adjacent Cell

Jul 22, 2008

I have a spreadsheet with 'due date' for returns in column L and 'received date' for returns, in the adjacent column M.

I would like to get the due date to turn red when it is overdue, ie. the date in the cell has arrived and no return was submitted. By trawlling the forum, I managed to accomplish this with the following in conditional formatting:
Cell value is less than or equal to =TODAY()

All's great.....but - I would like the date to turn back to black if I enter a date in the adjacent received column, column M.

In other words, I want to flag a problem if the due date has passed, but once I receive the return and enter the date I receive it, i would like the due date entry to revert back to the original formatting ie. black. So only the outstanding returns are highlighted.

View 14 Replies View Related

Refresh All Cells In Column After Changing Formatting?

Feb 26, 2013

I've been given some data and the date column is formatted as 'general'. If I amend it to the date format I prefer and click ok nothing changes. If I then click in the cell and press enter it changes the format to what I want. Is there anyway of refreshing all the cells so the format change takes effect?

I can achieve what i'm after by using find and replace to change '2012' to '2012' and '2013' to '2013' but i'd be interested to know whether there is a more recognised solution?

View 2 Replies View Related

Code To Colour Cells Dependent On Reference To Adjacent Criteria

Jun 11, 2014

I have developed the following code to colour cells dependent on reference to adjacent criteria (in Col D).

Is there anyway I can simplify this code to avoid three separate "For each" statements?

Code:
For Each c In Range("E12", Range("e" & lastrow))
If c = "" And c.Offset(, -1) "" Then
c.Interior.ColorIndex = 7

[Code] ..........

View 2 Replies View Related

Formatting Of A Cell To 2 Decimal Places

Feb 24, 2010

if I change the formatting of a cell to 2 decimal places, it appears as two decimal places (as it should) for example $88.88888 will show as $88.88

However, when I use this data in another application that displays this data it will display as 88.88888 still. I need to actually take the value and truncate it to 88.88 eg 8.8888888 will become 8.88

I have been using trunc by hand and wanted to try and find out if there is a way that I could write some sort of macro to do this for me each time.

View 14 Replies View Related

Use Conditional Formatting If 360 Cells Automatically Changing Colour Red

Sep 10, 2013

I have figure A1 column which total amount accounting at cells A31. I need figure 360 as a benchmark calculation perfectly been done. In this calculation 360 well off inside cells A18 although actual number is 363. If we use Conditional Formatting when had enough total in cells the achieve 360, cells colour will be transformed to red. What formula which need I used to change no matter cells on A1 to A30 if sufficient study 360 automatically cells changing colour to red

View 5 Replies View Related

VBA / Formatting Textbox To Number With 3 Decimal Places

Nov 21, 2012

I need to have textBox2. formatted to a number with 3 decimal places.

The code below is executed from the command button.

Code:
Private Sub CommandButton1_Click()
If IsNumeric(Me.TextBox1.Value) Then
Me.TextBox2.Value = Me.TextBox1.Value / 25.4
End If
End Sub

I found the code below but I cannot seem to figure it out

Code:
Private Sub TextBox2_Change()
TextBox2.Text = Format(Number, "0.000")
End Sub

View 2 Replies View Related

VBA Code - Color Changing Cells

Apr 29, 2009

I am trying to create a model that has a mixture of conditional formatting and data validation formulas within it, but have run into a problem in one area. Essentially, cell E10 is a Validation which pulls a drop down list of names. One of the options in this list is "Other".

I want to create a VBA code to make sure that cell E12 will get rid of any input, turn grey (color index = 15), and potentially lock (if possible!) if the "Other" is chosen by the user in cell E10. If any other value is chosen for cell E10, Cell E12 needs to remain unlocked and white (color index=2).

View 9 Replies View Related

Changing Cells Colors In Relation To Cell Input - NOT Conditional Formatting Ques

Mar 22, 2008

I'm a average excel user, i know my way around it and kow common and basic formulee, VB isnt a strong point, but i am willing to attemp anything for this, let me explain

Lets say in colum A I have a list of items, in colum B i have a check box, currently the check box is red, if i tpye a x it turns green due to conditional formating. That works fine...onto the problem...

Lets say in colum A i have my items but they are repeated...eg A1, A145, A166, A122 are all the same item, what i want is regardless of where i place the x each check box under coloum B either gets a X and turns green, or just turns green, i dont mind...

I dont think conditional formatting can cut this, though i may be wrong. Ive tried to use the IF function under condtional formatting but ran into problems...

View 9 Replies View Related

Code Changing Color Property Of Wrong Cells?

Apr 14, 2013

I have this code:

Code:
If .Range("K" & t) = "AUTO" Then
.Range("K" & t) = Format(Application.VLookup(.Range("A" & t), rcore, 54, False), "h:mmA/P")
With .Range("K" & t)[code]....

It is intended to change the font colour to white when the cell = "AUTO". It does, but it also changes the contents of the cell (like NA, and NR) to white when they aren't equal to AUTO.

View 2 Replies View Related

Varying Validation Drop-downs Based On Varying Cell Values

Aug 7, 2013

I am attempting to have cells in Column 'U' deliver different drop-down menus based on the corresponding value in column 'D'. I have created 7 named lists:

List_117G
List_152
List_JMET
List_XBAND
List_PACWIND
List_VORTEX
List_ROVER

Those lists will be called up based on 7 values in column “D”:
“G”
“152”
“J”
“X”
“D/E”
“V”
“R”

So far I have only been able to get this to work for the first category “G”. When I change the value of column “D” from “G” to “152” I no longer get a drop-down. Here is the formula I am using in the List function of validation.

=IF(D6="G",List_117G,IF(D6="152",List_152,IF(D6="J",List_JMET,IF(D6="X",List_XBAND,
IF(D6="D/E",List_PACWIND,IF(D6="V",List_VORTEX,IF(D6="R",List_ROVER,)))))))

View 2 Replies View Related

How To Code Detection Of Varying Equalities In Array

Feb 27, 2014

I have an array and I need to be able to detect when a varying number of consecutive array elements are equal. I want to be able to call the code and give the number of elements I need to find.

The following does not work but illustrate what I am looking for.

[Code] .....

I have been looking at ways of recording the number of equalities in the p loop, but I am sure there is a more elegant way.

View 2 Replies View Related

Combine Rows Of Varying Length And Varying Number Of Occurrences

Jun 28, 2012

There are 11,000 rows and 4,000 are unique. The goal is to merge the data down to the 4,000 records. Each of the unique entries shows up 1 to 15 times.

In trying to solve this, I wonder if I should break this down into the different # of occurances and implement specific solutions. e.g., There are

5700 entries that show up 2x
504 that show up 3x
24 that show up 12x

View 3 Replies View Related

Copy Non-adjacent Cells In A Row From One Spreadsheet To Adjacent Rows In Another

Jan 5, 2014

I have a workbook with 30 worksheets. Each sheet has 84 rows of data (start in 15 columns (A to O). I would like to create a summary sheet that only shows the most important data from each sheet.

The summary sheet would have 12 lines of headers and formatted crap at the top.
The Summary sheet header columns would be:

Site (A), Date (B) Health (C), Status (D), Critical (E), Task (F),
Dependencies (G), Owner (H), T-Date (I), Task Date (J), Mitigation Date (I)

The data in the sheets are not in that order, of course.

That
1. puts the name of the sheet I am copying from in column A
2. the deadline date in Column B (that date is always in C10 of each worksheet)
3. and copies Cells from Column A,B,G,H,I,O in any row in which the value in A is not "good" into columns C through H. I would like to paste those rows into the summary sheet. I have code that loops through the sheets and rows in each sheet to find the rows to copy. I can copy cell values directly from the active sheet to the summary sheet, but because I am copying a cell at a time, it takes 7 minutes. Yes I am impatient :)

Here is the code snippet where the copying is done:

Dim sh As Worksheet 'current worksheet
Dim DestSh As Worksheet 'worksheet in which to paste summary
Dim Last As Long
Dim CopyRow As Long 'row to copy
Dim LastCopyRow As Long

[Code] ........

ExitTheSub:

Application.Goto Sheets("KMARollup").Cells(1)
End Sub

I think there must be a way to use ranges to build an array of cell values and paste only once but I am lost here.

View 2 Replies View Related

VBA - Call Macros With Varying Names And On Varying Modules

Oct 2, 2013

I want to call a macro with a varying name that is within a module with the same name.

I have a module called Test1 and within this, a macro name called test1
I have a module called Test2 and within this, a macro name called test2
etc

On another module called Test8 (with the macro called Test8), this Test8 macro will call either Test1 or Test2 or Test3 etc depending on what I choose in an excel spreadsheet. So on sheet1, cell A1, there is a drop down with the options Test1 or Test2 or Test3 etc.

The following works to run the macro test1 from module test1 (when it does not vary i.e. i physically put in the name of the macro myself):

Sub Test3()
Test1.Test1
End Sub

The following works to run the macro test2 from module test2 (when it does not vary i.e. i physically put in the name of the macro myself):

Sub Test3()
Test2.Test2
End Sub
etc

However, if I try it so that the calling of the macro varies as below , it does not work:

Sub Test3()
MacroToCall = Sheets("Sheet1").Range("A1").Value
MacroToCall.MacroToCall
End Sub

View 7 Replies View Related

Macro Code To Average Multiple List Of Varying Column Ranges

Apr 4, 2009

I have a spreadsheet that has two different data sources (i.e., A and B). The amounts of these data sources (i.e., the number of columns) varies from sheet to sheet. I have to calculate the averages of these data sources independently and together. Because this data is spread across twenty or more spreadsheets, these calculations can be time-consuming. I want to do the following:
1. Locate the last occurrence of the first data source "A" in row and then insert a column after that cell.
2. In that cell, I want to get the average of each data source for each row of data (i.e., there are always 19 rows of data).
I want to do the same two steps for the second data source "B". Then, I want to insert a column after the "B" average and this column will be used to get an average of each row of data from A and B together. Please keep in mind that the number of data sources for A and B varies from sheet to sheet.
So far, I am working on code to try to " find" the text in a range (i.e., find the last instance of "A"), but I cannot figure out how to get it to get it to stop at the last occurrence and then insert a column. I have some ideas about how to calculate the average, but any of yours are much appreciated.
Also, the row with the type of data (i.e., A or B) is named because this function is part of a larger macro. Therefore, it is relatively easy to get to it.
I have attached a version of the file that displays how I want it to look.
The code I have thus far is:

Cells.Find(What:=A, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate

View 9 Replies View Related

Modifying Code To Reference Cells And Its Formatting?

Aug 7, 2012

I am attempting to modify the code below to, not only reference the ".Item(rCell.Value)", but also include it's formatting. The format for that referenced cell will not necessarily be a "certain" format..so I don't want to have to write out what specific formatting needs to happen.

VB:
If (.exists(Trim(rCell.Value)) And rCell.Offset(, 1).Value = "") Then rCell.Offset(, 1) = .Item(rCell.Value)

The entire code is as follows:


VB:
Sub FillVariablesOnlyBlanks()
Application.ScreenUpdating = False
Dim a, i As Long, rCell As Range, ws As Worksheet[code]....

View 9 Replies View Related

Conditional Formatting Code To Shade Cells

Mar 19, 2009

In B16:T24 I have cells that need shading depending on what code I put in them. I have 5 codes P, BH, S, ML, HD

I would like the cells to change colour, when I put P in them I want them to change to blue, when I put BH in them I want them to change to green, S I want to change to red and so on.

View 4 Replies View Related

Looping & Conditional Format: Finds A "J" It Will Apply Conditional Formatting To A Row Of 4 Cells Directly Adjacent?

Feb 9, 2009

I need to run a loop through a column of values (attachment col B) and when it finds a "J" it will apply conditional formatting to a row of 4 cells directly adjacent. The attachment is a theoretical before & after.

View 2 Replies View Related

SUM On Varying Number Of Cells In VBA

Jan 14, 2013

I am writing sum of few cells from the row above, to a single cell and then merging the cells.

I need to achieve this in vba but the problem is that the number of columns I need to use in the SUM formula can change month by month, though I know how many columns are there in each month and I am using A1 style to write formula in my code. I couldn't find any way to write formula in vba in such a way that you can change column name to variable (so that first sum covers columns 2 - 6 (or 2 + 4), second covers 7 (OR 2 + 5) - 10 (OR 2 + 8) etc.).

View 1 Replies View Related

Format All Percentage Cells To X Decimal Places

May 17, 2008

I would like to do the following: * Format numeric cells (cells with a percent sign) to zero decimal places. I have a set of macros that I am combining to clean up a data set and these are two of many (removing blank lines, duplicates, blue/bold, etc.)

View 2 Replies View Related

Use A Macro That Creates Sheets And Places Formula In Cells

Jun 20, 2006

I am trying to use a macro that creates sheets and places formulae in cells but the resulting formulae are not what I coded. Here is similar

Function CreateSheet(i As Integer)
Dim CellAddress As String
Set Adjustment = Worksheets("Sheet1").Cells(6, 3 + 4 * i)
Celladdress = Adjustment.Address(ReferenceStyle:=xlR1C1)
With Selection
.Offset(22, 9).Formula = "=Sheet2!B14*Rating!" & CellAddress
.Offset(23, 9).Formula = "=Sheet2!C14*K4*Rating!" & CellAddress
.Offset(24, 9).Formula = "=Sheet2!D14*K5*Rating!" & CellAddress
End With.............

View 3 Replies View Related

Sum Total For Varying Number Of Cells

Nov 30, 2009

----------A----------B---------C
1-------------------100
2--------11/29----150-------250
3--------11/29----300-------300
4-------------------200
5-------------------300
6-------------------150
7--------11/30----100-------750

Have column A with date, column B with subtotal, column C with Total. The Total (C) is made up of one to five subtotals (B). Subtotals to be included in the Total are those that come after the previous Total up to the row with a date. Only a row with a date has a Total. Is there a formula that can do this?

View 3 Replies View Related

Sumif Of Varying Range Of Cells

Apr 11, 2012

I'm trying to sum a varying range of cells based on conditions in another column. right now im trying =SUMIF(B:B, "Active", C4:C10)

The number it is returning is not correct and I'm not sure whats wrong. Also, is there a way to allow the range of cells to vary? Like if I wanted to insert a row and have it included in the sum.

View 2 Replies View Related







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