Macro For Selection Delete
Dec 31, 2008This is a piece of code from a macro that i am altering. I keep getting an error when i get to the 2nd line.
View 7 RepliesThis is a piece of code from a macro that i am altering. I keep getting an error when i get to the 2nd line.
View 7 RepliesI have a listbox in my user form and it has a Rowsource of A1:A225, I need to be able to select a value in the list box and hit Command_Button4 to delete it.
Private Sub CommandButton4_Click()
DeleteName
End Sub
Sub DeleteName()
ListBox1.Value.Select
Selection.ClearContents
End Sub
Also, is there anyway to ignore blank cells in the listbox?
I have a macro that prints out schedule information for my production lines. I recorded the macro and made a few changes. What it does is print out the page header, delete about a dozen lines and then print the remainder of the schedule. Often the the remainder of the schedule is not all relevant data as production has completed orders. What i want to do is, using an input box, ask the user what worksheet row he wants the body of the schedule to start printing from. Here is what i have now.
Sub auto_open()
Workbooks.Open Filename:="S:BI-K11.xls", UpdateLinks:=3
Application.WindowState = xlMaximized
ActiveWindow.SmallScroll Down:=-3
Rows("7:13").Select
Selection.Delete Shift:=xlUp
Range("A1:O26").Select
Selection.PrintOut Copies:=1, Collate:=True
roww = InputBox("Rows")
Sheet1.Range("A1").Resize(roww + 10, 2).PrintOut
Workbooks.Open Filename:="S:BI-K21.xls"
Rows("7:19").Select...............................
is where i would like the number 13 to represent the input box variable so that the rows to be deleted would be from 7 to "last row to be deleted - 1"
My userform has an update button that displays a listbox in a userform. The user selects from the list, chooses to update and another userform appears to request some additional information before saving it to a different sheet. This works fine, but how do I then delete the row containing the original item on the original sheet selected from the listbox at the same time?
View 2 Replies View RelatedI have a worksheet where I have restricted the users from scrolling around beyond a certain range.
Because of that the user is prevented from selecting an entire row.
There are some cases where the user should be able to delete entire row or range of rows.
How can I allow them to select say cells "C17:C35" [they would just hoghlight the range] and hit ctrl+d; which would trigger a macro and the macro in turn would delete all the rows in that selection [rows 17 through 35]?
I know some basic codes for deleting entire rows, but I don't know how to read first and last row of the selection under Target property.
Here is my
ThisWorkbook.sheets("sheet1").Range("M").Select
For Each cell In Selection
If cell.Value = ThisWorkbook.Sheets("Sheet2").Range("A").Value Then
cell.EntireRow.Delete
End If
Next cell
Range("a1").Select
End Sub
I want to remove all rows in sheet 1 that contain any value found in Sheet2 A I using XL 2003.
i'm looking for is that I have two lists via Data Validation, and when someone changes their selection in list A, i'd like for list B to auto-delete whatever value it had in it.
Also, on a different topic, i'd like to know how to hide certain sheets in a workbook from public view.
I have two listboxes where I can move tickers from left to right. This is synced with a sheet, such that the tickers also are pasted there too.
But if I use the remove button, I can remove tickers from the listbox, but I cannet delete them from the sheet. If I understand right the listbox only refer to what row the selected is, not what the text is...
And then its a bit tricky. I have tried a code where it just add the list one more time, after the itmes has been removed. And that could work if it hadn't been for the second column which also has a text, this column is updated after every ticker has been moved from left to right.
What I would like to have is a function that would know what the text in the row that I delete, or remove.
This is what I have so far:
Code:
Private Sub cmdMoveToLeft_Click()
Dim i As Integer, j As Integer, k As Integer
Dim RowsStart As Integer
Dim LastRow As Long
Dim Rows As Integer
RowsStart = Me.ListBoxX.ListCount
[Code] .......
I want to delete a sheet in a macro but when I run the macro, I always get a message warning and I have to answer the msg box to delete the page. Below is the macro command I am using.
Sheets("Tel").Select
ActiveWindow.SelectedSheets.Delete
How to create a macro that selects only the 2nd file in a folder to be opened instead of every file.
So far the code below is opening every file.
Sub ConsolidateAll()
Dim wkbConsol As Workbook
Dim wksConsol As Worksheet
Dim wkbOpen As Workbook
Dim wksOpen As Worksheet
Dim FolderName As String
Dim FileName As String
Dim Cnt As Long
Application.ScreenUpdating = False
[Code] .......
I seem to be getting myself into a complete muddle as was wondering if someone to help me with a Printing problem.
On the attached sample, i'm trying to write a macro to print the selection but only print where the status is "Active" to the ned of the selection. However, the spreadsheet is changing on a daily basis i.e. new lines being added and lines being taken off.
So, to take potential of user error out i wanted a macro to print the "active" selection.
I have data in cells C3 through E3, then a blank column, followed by data in cells G3 through I3. When I use excel to record a macro, it produces the following.
Range("C3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
However, when I run the macro, it only selects cells C3 through E3. How do I get it to continue through the blank column? I tried to make this example as simple as possible.
Is there any way this code (below) can be modified so that the macro runs without actually selecting the sheet it requires. The reason for this is so i can hide the sheet (Column Output 3) from view so the data isnt displayed. at the moment the sheet is on view and i would rather it werent. this is the code i have
Sub DistributeRows()
Sheet11.Select
Cells.Select
Application.CutCopyMode = False
Selection.ClearContents
Dim wsAll As Worksheet
Dim wsCrit As Worksheet
Dim wsNew As Worksheet
Dim rngCrit As Range
Dim LastRow As Long
Set wsAll = Worksheets("Column Output 2")
LastRow = wsAll.Range("A" & Rows.Count).End(xlUp).Row
Set wsCrit = Worksheets.Add
Set wsNew = Worksheets("Column Output 3")..............
I need a macro that can cut and paste a selection of 3 cells to a location one row above and 3 cells to the left. I want to run it each time manually from the right cell among the 3. the macro should therefore (when standing on the right cell of the 3):
1. select 2 more cells to the left
2. cut the selection
3. move 3 cells to the left and one cell up
4. paste
5. move the cursor back to the starting location
see attached pic for example.macro needed.JPG
I have an excel file with a date dropdown box. The date is populated from another sheet in the same file. I need to create a macro, which will select the latest date by default when the file is opened. Is this possible and if so could someone please lead me in the right direction? I am using Excel 2003 and the date format in the dropdown box is "dd-Mon-yy" --> eg "21-Dec-09"
View 9 Replies View RelatedI tried recording a macro but I am keep on getting an error. I need a macro which will print the selection of A1:D28 on a worksheet called Invoice. The print needs to be scaled at 165% of its normal size. i need it to be normal margins and if possible any printer.
View 1 Replies View RelatedIm having some problems with range selection in macros. Basically, what the macro does is Copy / Paste as Values in differet sectors of an active worksheet, so this is the code for each range of cells that I need to copy paste:
Code:
ActiveSheet.Range("C14:E15").Select
Selection.Copy
ActiveSheet.Range("C14").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
The problem with this code, is that because it specifies EXACTLY which range to select, if I add a row before that range the macro will be now selecting an incorrect range.
For example, say I have a value on cell A5, and the macro is set up to copy/paste that cell. Later on, I decide to add a row in A3, so the value I would need to copy/paste will now be in A6, but the macro will still execute on A5 (incorrect, as it should now execute in A6, and that is what I have to manually correct each time).
i am using user form to run some macro and i like that after running macro the cursor will return to the active cell , at the moment the cursor located on the user form.
View 9 Replies View RelatedI have is two spreadsheets with different data on them, but the only connector is the user ID, so I want the cell I select with the user ID to be copied it then switches to the other spreadsheet and finds the copied selection, it then takes the columns on the selection of A to J and pastes them back in the other columns in the other spreadsheet.
My only real problem is that I can't get it to use the selection.copy in the find to select the cells I need, any help would be great, thanks.
Code ( i put spaces bewteen the other parts and find function so you could easily see it):
Sub Macro1()
Selection.Copy
Windows("EMERA-employees-asof-06-Mar-2007.xls").Activate
Cells.Find(What:="(I want this to be selection.copy)", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Columns("A:J").Select
Application.CutCopyMode = False
Selection.Copy
Windows("SMSReportResults.xls").Activate
ActiveCell.Offset(0, 6).Range("A1").Select
ActiveSheet.Paste
End Sub
I have a macro that I am running "onentry" of a worksheet. The problem is that I have some cells that are validated to allow a list. If I manually type a word from the list in the validated cell the macro runs. However, if I make a selection from the list the macro does not run. I guess vba does not see my selection as an entry.
View 9 Replies View RelatedI've recorded a macro which selects "1" in a filter drop-down box then prints some pages, then comes back and selects "2" in the filter then prints some pages, etc etc etc.
I've looked at the code for this and it treats the "1", and the "2" etc as text each time - originally I had the filter on names, but the names change each time I need to do this whilst the process doesn't, so I filtered on numbers instead.
However, I would have to enter the repeated blocks of code down to 1000 to get it to select down to "1000" in the filter. About 3/4 lines each time but with me manually typing in 1, 2, 3, 4 .... 999, 1000.
Is there a way to say in VBA 'repeat filter selection until you've run out of numbers then come back to "All" and stop ?
I have a simple macro that allows for inserting cells above the selected cell. It actually inserts 2 cells: above the selected one and above the one immediately to the right on the same row.
I need to add 2 features to prevent mess ups:
- The Active cell should only be on column "N" and after row 15 on the sheet. Any other cell selection should be ignored or ideally pop a warning to prompt user to select a > N15 cell.
- An OK/Cancel dialog box that pops up before execution and reads:
"Are you sure you want to skip "text_of_selected_cell" for date "text_of_Column-13_cell_on_same_row"?"
Sub SkipDayRelative()
ActiveCell.Offset(0, 0).Range("A1:B1").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End Sub
I have got 8 sheets in a workbook having the following names first one is Main,and others are Aw,Nzm,Mhk,Gul,Qta,and Hdr.
I want a ComboBox in every sheet displaying names of all sheets in combobox and when i select a name of sheet from combobox it goes to that sheet after hidding sheet where selection was made and running macro codes which i have developed for sheet. I want only one sheet display on the screen when one selection is made other one is invisible.
I get 40~100 page PDFs of purchase orders every week. Each page has one part number and its open order and forecast information. Some pages have a few line of information, some have many lines.
I convert this file into a txt file.
I then create a macro to import it as space delimited and format it.
What I need to do it get rid of the header/footer information on EVERY page.
When the txt file is created it doesn't have any page marks.
The header has "ABC Widgets" as the customer name and then 10 rows of unnecessary information. If I do a Find ALL for "ABC Widgets" and select all, it will delete that header line at every instance, but the leftover selected cells then start not-lining up (meaning I can't just hit "delete row" 10 times and have it pick the right row--the rows don't line up any more and each instance is -1 row offset.)
Is there any way to extend the selection of non-contiguous rows (starting with ABC Widgets) down by 10 so I can delete them?
I am looking to run a marco for a selection range, and the selection range could vary in size.
Using the Macro recorded (whilst turning on the relative reference) the Macro runs for a defined number of cells. I would like to run certain Macro, for different ranges of cells.
I have a macro I'd like to run when a worksheet tab is selected. The macro updates content in various cells.
That action is now triggered with a command button (linked to macro), but I'd like it to take place when the user selects that worksheet tab.
I see where I can use the following to bring up the color pallet
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred
when copy/pasting, but IS if the keyword uses "quotes".
Sub MyColors()
' brings up the colors dialog
Application.Dialogs.Item(xlDialogColorPalette).Show
End Sub
But I don't know where to go from here. I would simply like to have cells selected, run the macro, select a color from the dialog, press the ok button, and have the selected cells colored per the color selected in the dialog. (Of course, pressing cancel would exit without changing any colors.)
This recorded macro inserts a line below the cell that active when it was first recorded. It then copies some text and a formula to the line that was created.
Sub Macro11()
Rows("10:10").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A9:E9").Select
Selection.Copy
Range("A10").Select
ActiveSheet.Paste
Range("H9").Select
Application.CutCopyMode = False
Selection.Copy
Range("H10").Select
ActiveSheet.Paste
Range("F9").Select
End Sub
If you run this macro again at a different cell position, it goes back to the first starting position and repeats the same action. I see that the cell references from the first recording are fixed in the macro. I can't figure out how to make the macro use the new current cell position as the starting positiion when it runs again.
can i use a combo box with a dropbuttonclick to run the macro only when the arrow is selected . The problem I am having is the macro will run on the selection of the arrow which is whatt I want but it also run when I make a selection it the combo box
I have selected 6 rows and 2 columns in a sheet and I have a button in the same sheet.Now I click the button it triggers the button_click where I have put msgbox to popup.But I need this selected value in message box instead of the my hard coded string.
sample value in the selected cell:
1,1.005
2, 3.006
.........
..........