Format A Range Of Cells, Columns And Rows Will Vary In Length
Jun 16, 2009
I created a macro on an Excel spreadsheet:
Sub Macro1()
Range("C11:D19").Select
Selection.NumberFormat = "$#,##0.00_);($#,##0.00)"
Range("E5:E20").Select
Selection.NumberFormat = "0.00%"
Range("D24:E43").Select
Selection.NumberFormat = "$#,##0.00_);($#,##0.00)"
ActiveWindow.SmallScroll Down:=24
Range("D58:E339").Select
Selection.NumberFormat = "$#,##0.00_);($#,##0.00)"
ActiveWindow.SmallScroll Down:=57
End Sub
When the macro is run, it works with the exact amount of data that I've entered.
However, because I have specified a specific range, if I add a row or column of data to the spreadsheet and run the macro again, it throws the whole thing off (certain cells get formatted when they shouldn't and others aren't formatted)
How do I tell the macro to look in the spreadsheet for varying ranges of data and format those cells?
View 9 Replies
ADVERTISEMENT
Feb 8, 2011
If I have a cell with this info: [6126]BOB SMITH
What formula can I use to get BOB SMITH. The length of the name will vary. The number will change, but will always be 4 digits and will have the brackets. [XXXX]
View 8 Replies
View Related
May 29, 2007
i have data that will vary from item to item in the $ of rows associated
and the # of columns to be dealt with.
item1 Line 1
Line 2
Here i want to have a formula put and copied across X columns
item2 Line 1
Line 2 other data going across in the columns
Line 3
Line 4
Here i want to have a formula put and copied across X columns
item3 Line 1
item4 Line 1
get my meaning??
columns involved will be known before i get to this bit of code !!
as an example lets say it's 8 columns
using the record macro i get this bit of code
Range("E14:M14").Select
Selection.FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"
This is fine but i don't know what row or the columns are before i run the macro so the Range
("e14:M14").select wont really work.
I've sent sometime going through MRexcell searching for tips but found nothing also googled for dynamically pasting across unknown columns
this is close to my idea in my mind conceptually
Range("C2:C" & LastRow)
but it doesn't make the columns dynamic eg column 8 being = H and then P = 8th column on and the last with data.
View 9 Replies
View Related
Feb 5, 2009
You can always add numbers together. however, how can you vary columns based on a number?
for example, i can always do things like the following to change the number of rows selected in a column based on the variable numRows.
View 2 Replies
View Related
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()
Sheets("Risks").Select
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
[code].....
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
Mar 19, 2008
I'm working to build a macro to help clean up data I download out of our company's online resources. I know that the data will run from column A to N but the number of items (and thus number of rows)will change. I need to sort all used rows except for the last one (which containes totals and I don't want to include in my sort). So right now I'm just trying to figure out how to select from A3:NX, where x is the row above the last used row.
What I've managed to find so far on the forums is
Offset("$A$3", 0, 0, (Match(9.99999999999999E+307, "N:N", 1) - 1), 14).Select
which I think should find the last row in N to have a number in it, minus 1. However I'm getting a compile error that function or sub are not defined. (seemingly refering to the Match, but I'm not sure).
View 6 Replies
View Related
Aug 25, 2006
How do I define a " Range Name" that is fixed? So if I insert a row above the range it has no effect on the orginal range.
IE: Range Name "MyRange" = A10:A100
I insert a new row at A4 then "MyRange" = A11:A101
I want it to stay at A10:A100.
View 5 Replies
View Related
Sep 23, 2013
I am using MS Excel 2007 and I am trying to create a macro which will copy column E and paste the data in column E to the bottom of column D. However each week the amount of rows in these column with vary, they will always be the same amount of rows in column E as in column D but there may be 20 rows one week and a 100 rows the next.
The formula I currently have is below but this will only work for a specified number of rows. How I could change this to work for any number of rows?
Code:
Sub IPT()
'
' IPT Macro
'
'
Range("E1").Select
[Code] .....
View 2 Replies
View Related
Sep 17, 2013
I'm trying to avoid using merged cells or text wrapping with altered row height to display some text in multiple rows - similar to using centre across selection to have a header across multiple columns without merging. The guys that use the sheet type a comment that is relevant to five rows and the easy solution here would be to just type the first portion of the comment in the first row (about 30 characters will display in the column width available), then put the next 30 characters in the next row and so on but the guys keep getting lazy and merging the cells so they can type the comments more easily. I can lock the sheet or force validation but I think there's a better solution.
I can effectively "wrap" the text across the five rows the header is relevant to by using a formula to pick up everything except the first 30 characters of each cell. Ie if they type whatever they want in cell B16 then I can use this formula to break it in to 30 character lengths to "wrap" it in to the next four rows:
=IF(LEN(B17)>30,RIGHT(B17,(LEN(B17)-30)),""),
And I'm sure it would be easy enough to use search with the formula to break it where there is a space in the text so partial words don't flow over.
BUT because the text ends up slightly different widths I want to use formats to force only 30 characters to display (whilst keeping the remainder of the text string intact). I can't figure out the syntax to format only 30 text characters to display but you can easily do it with numbers and dates and so on.
View 1 Replies
View Related
Jun 11, 2009
I have VBA code to set a password on multiple worksheets in a workbook. I new need to force a check in the "Format Columns" and "Format Row" checkboxes. The current VBA code is:
View 4 Replies
View Related
Jun 27, 2012
I have tried many ways to get script to do the following without success. I need a vba formula that identifies claims in a Range that are not 12 characters in length and do not have "00" at the beginning & end of the number. The format of the number should be "00########00".
View 3 Replies
View Related
Jul 24, 2009
I have a worksheet on which users will enter data one row at a time, in columns A-K. When the user starts to enter data in a new row #, that is, when they make any column in the next, unused row have non-blank value, I'd like the sheet to update the borders of the row for columns A-K. I want the Range from A1 to K# to have full borders, so that the whole data set is outlined and easier to read.
For a bonus, I'd like the formulas from the previous H, I, and J cells copied down into H#, I#, and J#, adjusted appropriately for their reference changes.
Normally, I would work around the edges of such a VB problem by recording the actions manually and then modifying that code as I learned more. But I'm not sure if what I've done is the right way to start that process. I think that if I use the CurrentRegion property, and the Worksheet_Change event, I'll be well on my way.
View 2 Replies
View Related
Feb 25, 2008
I've been trying to get around the 3 rule limit for conditional formatting,
and I've found the code I need on the site
[url]
I've changed it to suit my needs
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
If Not Intersect(Target, Range("A1:A2000")) Is Nothing Then
Select Case Target
Case Is = "Test"
icolor = 6
Case Is = "Test2"
icolor = 12
Case Is = "Test3"
icolor = 7
Case Is = "Test4"
icolor = 53
Case Is = "Test5"
icolor = 15
Case Is = "Test6"
icolor = 42
Case Else
End Select
Target.Interior.ColorIndex = icolor
End If
End Sub
This works great for one cell, but I need to format a row range based on the single cell.
So if Test is entered into A1, then it changes to yellow, I also need the next 6 cells on the row to change too- In this case [B1:G1].
But it needs to cover the range in the code A1:A2000
View 9 Replies
View Related
Jul 11, 2007
my excel setting... I'm not able to see some of the numbers (in currency/accounting) in excel file, it shows as many "#" sign, and it's not due to the column width. The same file can be seen in other computer.
The format setting is the same in all the cells but only certain rows/cells' numbers appear like "normal".
View 9 Replies
View Related
Jul 26, 2013
how can I make this simple macro sum columns that will be of variable length? I would like the sum to appear as the last entry in that column and highlighted.
VB:
Range("H36").Select
Selection.FormulaR1C1 = "=SUM(R[-34]C:R[-1]C)"
Range("J36").Select [code]....
View 7 Replies
View Related
Jan 22, 2006
I have a SS I would like to reference a cell in a column which changes in
length. In this case, I would like to reference the most current date in a
column.
Is there a simple method for doing this, as the data will routinely be
different lengths in that column.
Further, there is Data on the Horizontal that I would like to reference to
another cell in another sheet that would correspond to this date. Can anyone
give any suggestions as to the best way to accomdate this?
View 11 Replies
View Related
Jul 20, 2012
I have 5 columns with data in each
I want to create a 6th column that looks to the columns on the left with data in ti and concatenates all data in the 5 columns and puts it into one cell in the 6th column however put a space between each break of data so that it can be distinguished which bit of data was in what column previously.
The challenge is the new 6th column can only contain 30 characters - When it exceeds 30 characters then create a 7th column and put the rest of data in the 7th column, again the 7th column can only have 30 characters so if exceeds this then put the remaining characters in a 8th column
There will never be more than a total of 90 characters in the original 5 columns so there will only need to be scope for a maximum of 3 additional columns
So for example
Column A had two words in it that totaled 20 characters (the space between the two words is also counted as a character)
Column B had two words in it that totaled 20 characters (the space between the two words is also counted as a character)
Column C had a word that contained 10 characters
Column D had a word that contained 5 characters
Column E had a word that contained 10 characters
Then the result would be
Column F would only have the data originally held in Column A (because it can't include Column B's data as this would exceed the 30 characters)
Column G would have data that was originally held in column B and column C - with a space between B and C data
Column H would have data that was originally held C, D and E - with a space between C, D and E data
Another point to consider is if in one of the orginal 5 columns had say 3 words in it and lets say the 3rd word is the word that exceeds the 30 character limit, then the whole of the third word is to be carried oved to the next new column, I can't have words cut in hlaf with one half in Column 'F' and the other half in Column 'H' for example.
View 1 Replies
View Related
Oct 2, 2012
solve this task with a formula or a macro?
I have this strange number data stored by columns. Each cell contains one number series of different length from 1 to 13.
Needed results 1, Needed results 2
7409998765 7409998766 , 9998766567876, 7409998765 9998766 9998766 7409998766 9998766 9998766567876 9998766 9998766
I need to look-up and bring in one cell for each row only the 10 length numbers separated by space and in another cell the 13 length numbers space separated also.
The number of columns containing data is different from row to row ( from 2 to 60)....and the rows..are thousands..
View 7 Replies
View Related
Jan 29, 2014
Wondering if it is possible to conditional format cells in "Jan"-"Dec" columns based on "Next" column data?
What I need is (lets say fill colour to differ) in one cell per row, based on latest input and "next" data.
Month Avg
Date
Jan
Feb
Mar
Apr
May
Jun
Jul
[code]......
So for example:
row2: May is latest input so need fill in cell +2("next" column data) from may. In this case July
row3: Feb is latest imput and "next" also 2. Result should be Apr
row8:May is latest input, "next" is 6. Res should be Nov.
Finally, only one cell per row to be highlighted so need to overwrite colour fill when new data input in a cell already colour filled.
View 9 Replies
View Related
May 2, 2012
I have a column of data where the seperate entities are divided by blank rows. for example: i need to calculate sum(G3:G15) then skip the blank row (G16) and calculate the next group, say sum(G17:G50) and export that import to a new worksheet.
The issue is that the column lengths vary from day to day so the blank rows will not be in the same position.
View 2 Replies
View Related
Mar 27, 2014
I've set up a filing system which saves sheets/ workbooks based on the value of a cell - Range("B1") Everything works great apart from when ThisFile String length exceeds 31 characters which you may know is the max useable character length for a sheet name - I had no idea! 8-0
Is there a way i can check if string length exceeds 31 characters then, if it does, shorten it to 31 characters?
[Code] .....
View 2 Replies
View Related
Oct 24, 2012
Using the following code to remove empty rows based on whether a specific range of columns is empty. The code works if the cell has a zero, but not when the cell is blank. An example of the data is attached.
VB:
Public Sub DelRows2()
Dim Cel As Range, searchStr, FirstCell As String
Dim searchRange As Range, DeleteRange As Range
[Code].....
View 1 Replies
View Related
Sep 8, 2009
I´m having aproblem with Excel 2007 about Conditional Formatting. I have a row of Dates for example 02-01-2009 03-01-2009 04-01-2009 , etc in different columns.
Then what I want to do is use Conditional Formatting to Format cells on several rows below according to the day (if its weekend paint red, if not, dont do anything). I'm using the "Use a formula to determine which cells to format" and the condition is (supposing the cells with dates are A1 to C1)
=WEEKDAY(A1:C1) > 5 .
So with those 3 dates provided lets suppose Januar2nd is not a weekday, so the outputIwant is: Red White White, (Next Row) Red White White, etc for several rows.
Now what I think is not right is it only works for the row in which I have the cursor so its like: (Lets imagine I selected 3 rows on which I want to see that output) Red White White (The row in which the cursor is works fine), but the next row goes Red Red Red and the third the same.
View 5 Replies
View Related
Sep 4, 2012
How to create a code formula to calculate the arc length from a given chord length?
If you know the radius of the major circle.
Say the chord is 50mm and major circle dia is 72mm (radius 36mm)
arc from chord.jpg
View 5 Replies
View Related
Jan 9, 2010
My worksheet contains data with the reaction times on a psychological test. Each respondent in the test has 280 rows in my excel sheet.
The 'perfect' length of the row, is from A to M. When an error is made in the test, the length of the row will increase. So the error length can be A to AA.
For me it is important to analyse the error. So I would like to give a perfect row length, the value 1, and an error row length a value 2.
So, in conclusion:
If:
Cell length = A1 - M1? --> Copy A1 B1 C1 (A B Cof that row) to Sheet3, and give D1 in sheet 3 the value 1
Cell length >= A1 - M1? --> Copy A1 B1 C1 (A B C of that row) to Sheet3, and give D1 in sheet 3 the value 2
View 9 Replies
View Related
Nov 26, 2009
Using Excel 2003, Column E has a varying and unpredictable number of rows, which only the final 252 rows are of significance. I need to compute the following formulas, here written in English as I can't determine the proper terminology to accomplish this task in Excel:
Final Row with a number in Column E/average (final 252 rows with numbers in column E)+
Final Row with a number in Column E/average (final 126 rows with numbers in column E)+
Final Row with a number in Column E/average (final 63 rows with numbers in column E)
Once again, what makes this not straightforward for me is the column may have wildly varying numbers of rows.
View 6 Replies
View Related
Jul 29, 2014
I have a table in excel in which every line has as many values as the days of the month (e.g. 31 values first row, 28 the second..) and it goes from January 1948 to July 2014. So it ends up having around 800 rows.
I need to put all of those into a column, but it gets hard because the rows have different lengths. I have seen in this forum some solutions that apply well when the table is regular, but I'm stuck in trying to get a solution for when it's not. I have tried to record a macro using TRANSPOSE, but then I cannot change the cells into this formula in the editor in order to create a loop.
I also have to consider leap years.
View 4 Replies
View Related
Jun 9, 2009
I need to copy the value and format of a range of cells, is there a way to do this in one step rather this:
View 8 Replies
View Related
Apr 28, 2012
Is there a way to conditionally format a range of cells from VBA?
I want the cells to turn red yellow or green when i type into that cell r, y, or g.
I can easily select the range of cells, but dont know how to format them.
View 4 Replies
View Related
Mar 6, 2014
I am using the following range to copy data from Column A (from rows 3 on the the last row). How can I include Columns B and C into this range also, but still using Column A to find the last row?
[Code] .....
View 9 Replies
View Related