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.
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"
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.
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
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?
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
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
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.
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??
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.
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.
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?
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
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?
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
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.
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 ...
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.
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.
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.???
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.