Writing VBA Code To Add Borders To Selection

Mar 4, 2008

I got some code from an old discussion thread


Sheets("Reference").Select
Range("d9").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select

Dim myBorders() As Variant, item As Variant
myBorders = Array(xlEdgeLeft, _
xlEdgeTop, _
xlEdgeBottom, _
xlEdgeRight, _
xlInsideVertical)

View 9 Replies


ADVERTISEMENT

Code For Range Borders (short)

Dec 4, 2009

This ia a recorded code to draw borders around cells on a given range

I am sure it can be shortened to 1-2 sentences!


Range("J11:O16").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic

View 9 Replies View Related

VBA Code For Applying Borders To Ranges

Mar 12, 2009

I need to apply borders to a certain range. Is there anything I can do to shed some fat (code) off the macro below?

Range("A8:AD100").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)

View 6 Replies View Related

Writing Vlookup Into VBA Code

Aug 15, 2007

I need help writing the VLookup function into a VBA macro.

I currnetly have a macro that generates a list of companies in column D on Sheet1. There could be a different number of rows populated every time the macro runs.

I also have a list of all the possible companies next to their e-mail address on Sheet2 (company in column A, corresponding e-mail in column B).

I know Vlookup can search sheet2 and populate the correct e-mail address on sheet1, but I want a VBA solution in which it will automatically see how many rows of companites I have, perform Vlookup for each company, and place the corresponding emails in sheet1, column E.

View 9 Replies View Related

Writing Long Lines Of Code

Aug 29, 2007

I've written a piece of code that is so long, I have to use the scroll bar to see the whole of it, which isn't very user friendly

if there's a way of splitting long lines of code over say 2 or 3 lines, so I can read the whole thing without having to use the scroll bar? I've noticed some people use _ at the end of the code and then continue writing on the next line, but when I do this, I get an error message saying

"Compile Error : Expected : line number or label or statement or end of statement"

View 9 Replies View Related

VBA Code Quicker Than Just Writing Out The Calculation In VBA

Oct 9, 2006

Does Excel handle formulas written into the VBA code quicker than just writing out the calculation in VBA?

I have a section where I use the following formulas, sumif, countif and a combo if iserror sumproduct in the VBA code...runs rather slow at this point and was looking at a way to speed things up.

View 9 Replies View Related

Writing The VBA Code For The Objects Created During Execution.

Apr 27, 2006

See the attached Workbook, which explains the problem easier.

View 9 Replies View Related

Writing Code To Copy / Insert And Paste To Worksheet

Oct 11, 2013

writing a code where i can copy a worksheet (Sheet1), insert a new worksheet at the END (as the last worksheet), and paste to that new worksheet (which will have a different name each time a new one is added). I am using the code below, but it adds a worksheet after Sheet1 instead of at the end, and it also adds another weird worksheet that says "Dim Worksheet" in one cell, and "Set newsheet = Sheets.Add(After:=Sheets(Worksheets.Count), Count:=1, Type:=xlWorksheet)" in another. This is not in the VBA window, it is just text in a cell in another inserted worksheet. I only want one worksheet added at the end that I can paste too (knowing that the inserted sheets will always have new names).

Code:
Sub CreatePercentageSheet()
ActiveWorkbook.Sheets("Sheet1").Copy _
After:=ActiveWorkbook.Sheets("Sheet1")
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Paste
End Sub

View 2 Replies View Related

Difficulty Writing Code For Changing Font Color If Cell Contains Specific Text

Aug 11, 2009

I have a spreadsheet that will contain about 5-15 rows with a letter "S" in the column. If this letter S appears in the column, I need its entire row to change font color to RED and then change that row's value in column L to a negative number. is there any easy way to do this?

View 14 Replies View Related

VBA Bold Selection Code

Oct 9, 2008

i'm using the following code to make a selection bold or not (basically as a replacement for the bold button). It works fine unless you select a group of cells...some of which are already bold and some of which are not...in this case it doesn't work....here is the code

View 2 Replies View Related

VBA Code On Filling A Selection With Series

Dec 20, 2011

whats the vba code in filling a selection with a series 1 ,2 ,3, 4, 5, and so on?

cant seem to find it in google and cant make it out on macro recorder

View 3 Replies View Related

Pivot Items Selection Code

Nov 23, 2006

I have a userform, on the user form I have a combo box. when i select an item from the combobox list. I want it to show only that item in the pivot table. here is my code.. Can anyone see where im going wrong? or what i need to ammend to achieve this?

Dim i As Integer
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Description")
For i = 1 To .PivotItems.Count
If i = ComboBox2 Then
.PivotItems(i).Visible = True
Else
.PivotItems(i).Visible = False
End If
Next
End With

View 9 Replies View Related

Trying To Use Vba Code To Evaluate Each Row In A Highlighted Selection

Jul 22, 2009

I have a worksheet (with if statements) that I throw numbers from a report into and it uses those if statements to calculate the number of items and money earned. The problem is that sometimes employees use different key words for their items so the formulas dont pick them up and this skews their results for the month. Also it's hard to see where someone messed so I'm trying to write a code that reads each row for a given selection and calculates the sum and if that sum is 0 then we can look for where the employee made an error. This is what I have:

Dim RngToSum As Range
Set RngToSum = Selection.Rows
For Each Row In RngToSum
If Application.WorksheetFunction.Sum(RngToSum) = "0" Then
MsgBox "Lets play find the error"
Selection.Rows.Interior.ColorIndex = 3 'red
Else Application.WorksheetFunction.Sum(RngToSum) 0 Then
MsgBox "Congrats there's no errors"
End If
End Sub

The problem with the code is that I want it to read every line and if there's no errors then have it say "congrats no errors" after ALL rows have been checked because right now it pulls a msgbox per row and I don't want to go through hundreds of no error msgboxes. However, if even just one line has an error then have a msgbox come up.

Also there's something weird where this code wont pick up an error for a row if i highlight two rows (one row without an error and one with) but if i highlight just rows of zeros then it'll pick it up.

View 9 Replies View Related

Code Not Working If No Selection In Listbox

Jun 16, 2006

Why this code doesn´t enter in the if condition when i don't select any item from the listbox

semana = ListBox1.Value
If semana = Null Then
MsgBox ("Need to choose one item!!!")
Else
emd = Range("A48").Value
End If

View 3 Replies View Related

Selection.Replace Code Not Working

Jul 14, 2006

This one has really got me stumped:

Sub NCR()
Application.DisplayAlerts = False
Workbooks.Open ("J:AcctMgt3NWFMScriptingScriptsDailyReportsNCRNCRvdn.xls")
Sheets("NCRvdn").Columns("B:B").EntireColumn.AutoFit
dRow = Sheets("NCRvdn"). Range("B1").Text
dMonthDay = Format(dRow, "mmdd")
dDay = Format(dRow, "dd")
dPrevDay = dDay - 1
dMonthName = Format(dRow, "mmmm")
dMonthNum = Format(dRow, "mm")
dYear = Format(dRow, "yy")
dPrevDay2 = dMonthNum & dPrevDay.............

This opens the first file and dRow="7/13/2006". The next file that it opens contains links to information from the previous days. Without VBA you just drag the previous day down, select the row of data and do a replace all, say from 0712 to 0713. As you can see I even tried to make it use the specific data I wanted versus the variables; still doesn't work. What really gets me is that if I go back to the sheet after this code runs, I go to EditReplace, replace all "0712" to "0713" and it does it. It has to be the code then right??

View 3 Replies View Related

VBA Code For Printing Worksheets That Are Hidden From A Selection

Jan 19, 2013

I have a workbook with various pages that are all hidden except the main page, on the main page it allows users to select items froms drop down boxes that returns a figure to cell B7 on the selection page.

What i would like to do is press a command button and the hidden worksheet that relates to that figure in cell B7 opens which allows the users to print it then after printing or closing the workbook is hidden again.

View 4 Replies View Related

VBA Code To Close Userform After Data Selection Only?

Sep 11, 2013

I have a list of 10 shops as a list box named lstitems i need the user to click one of the 10 shops and when they click the selected shop it tells the name they selected. then i require a Quit button that transfers the selected Shop to cell D3 & then closes the userform, but if they do not pick a shop it will ask them to pick one before it closes. so they must select or it will not close.

View 9 Replies View Related

Stop Code Firing On Selection Change

Nov 22, 2006

how I can disable an InputBox? I've got some code that whenever someone selects a cell in a specified range, an input box pops up (running a macro) - this can get annoying sometimes though if just browsing. Does anyone know a macro where I can "disable" this?

View 4 Replies View Related

Combobox List - Pivot Items Selection Code

Nov 23, 2006

I have a userform, on the user form I have a combo box. when i select an item from the combobox list. I want it to show only that item in the pivot table.

Code:
Dim i As Integer
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Description")
For i = 1 To .PivotItems.Count
If i = ComboBox2 Then
.PivotItems(i).Visible = True
Else
.PivotItems(i).Visible = False
End If
Next
End With

View 9 Replies View Related

Code To Stop A Worksheet Selection Change Macro Running

Aug 17, 2009

I've got a worksheet_selectionchange macro on a sheet, and another macro that you can run after it. The issue is that when the second macro runs, it also runs the selectionchange macro, and wipes some of the info that the second macro should be copying.

Is there a piece of code that I can use in the second macro to block the selectionchance code from running until it's compelte?

View 6 Replies View Related

Create Surface Chart Via Macro Code Based On Selection

May 28, 2008

I want to write a macro to add a surface chart for a Data Range which includes 6000 data points. But the series selected for the chart don't cover all Data Ranges, only part of them.

Public Sub AddChart2(LastRow As Integer, LastCol As Integer)

Dim cht As ChartObject, currentSheet As Worksheet
Dim rng As Range, newRow As Range, srcRange As Range
Dim colIdx As Integer

colIdx = 5

View 7 Replies View Related

How To Skip To Next Section Of Code When Filtered Table Returns No Values For Selection

May 1, 2014

I'm making a macro that filters a data set and then inputs a value into all of the rows for a certain column. When no results show up for the filter I receive a runtime 1004 error because there are no cells to select.

Here is my code:

Sheets("External Buys").Select
Range("G5").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Raw Data").Select
ActiveSheet.Range("$A$1:$AU$10432").AutoFilter Field:=39, Criteria1:= _

[Code] ......

View 1 Replies View Related

Borders Around The Codes

Mar 22, 2007

I have a spreadsheet containing data in coloumns A to L.

Where all the codes in column B are the same then a border must be placed around all the codes that are the same i.e the border must start in Column A and end with column L.

provide me with the code the will put borders around the codes in column B that are the same ...

View 9 Replies View Related

Missing Borders

Oct 2, 2008

I have created a 4 page chart in landscape with text in each of the 4 columns in the chart.

When I looked at it in print preview the chart did not fill the page and so to widen the last 2 columns I dragged them over to the right hand margin. I am still definitely within the right hand dotted line showing the margin limit.

The problem is that I cannot now put a border line down the extreme right hand column. Every time I click on any of the border instructions in the Font tab nothin appears on the right hand side of the box.

View 9 Replies View Related

VBA For Shading And Borders

Feb 4, 2010

I am trying to write vba code that will highlight the row in the range if a field is over a certain percent. The column number won't change but the number of rows will. I'd also like the code to automatically work on all tabs of the workbook when a button is clicked.

Data Info:
Currently there are 4 tabs, but can have more/less
Columns used are A:O
Data for shading starts at A3 and should go to however many rows have data and ignore blank rows
Formula should be if data in column E is over 10.00% then the data in that row A:O should be shaded in the color off yellow & have black thin orders
If the data in column E is not over 10.00% then the data in that row should not be shaded but still have thin black borders.

View 9 Replies View Related

Paste Without Borders

Aug 19, 2007

Is it possible to stop excel from pasting border formating with cell data other than to select paste special-all except borders?

View 5 Replies View Related

Borders Macro Don't Line Up

Jan 22, 2014

The attached file works with 3 Drawers and 3 Doors but if I use 2 Drawers and 2 Doors the Borders do not line up. I think the Drawers are right the Doors appears to be the problem.

Same thing happens with 3 drawers and 4 Doors. It has and extra border on the right side.

See Attached : ozgrid cabinet error.xlsm

Also I would like for the Measurements to be in the cell to the right of the left hand border and center across each of the sections.

Change B3 and B4 to 2 then click draw. 3 and 3 work 3 and 4 don't but 4 and 4 does.???

View 2 Replies View Related

Removing Borders For Printing

Jul 6, 2009

I want to remove some cell borders for printing so that on paper it will look like 2 separate tables (ie, I want a space between the 2 tables). I have tried removing the borders and changing the colouring to white but they still show.

View 5 Replies View Related

Conditional Formatting - Borders

Jul 9, 2009

i am trying to do the following but having trouble getting my head around it!

if a2=0 then b2:b13=border

View 10 Replies View Related

How To Change Thickness Of Borders

Aug 20, 2013

I need to change the thickness of the borders line but I couldn't find out how.

View 6 Replies View Related







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