I have an excel sheet in which there is one table with a drop down and one normal excel cell. I try to clear the contents of the table and I have done it through
range("X").ClearContents
but the problem with it is it is going to clearing the content but I'm able to see the table borders with it.
When I have used
Range("X").Select
Application.DisplayAlerts = False
Selection.Delete
Application.DisplayAlerts = True
Range("X").Select
Selection.ClearContents
It deletes the table (both content and borders) but it I can see the formula in the drop down is missing ie the drop down cell has become normal cell.
Thanks in Advance!
You can use the ClearFormats() method, this will remove the table border.
Also, to clear contents, you do not have to first select the range. Take an advantage of the With statement
With Range("X")
.ClearContents
.ClearFormats
End With
The above should achieve what you're after.
Related
This sort of follows up from my previous few questions on the same workbook.
I have two sheets, the first being Car Search, which contains a form (NOT a VBA form, just a normal table that appears like a form) to fill in. The second sheet is Raw Data, and will contain all the information entered in the Car Search sheet. It will be displayed row by row (see 2nd image).
In the Raw Data sheet, I am using the formula =""&'Car Search'!B3 to copy the contents of cell B3 in the Car Search spreadsheet.
My question is: If I had a new Car ID value, how can that automatically be entered into the row below?
Essentially, I am trying to use the form to capture all data for new cars coming in, and then I would like all that data to appear in the second sheet in their respective rows/columns.
Any help much appreciated! :)
EDIT:
Good news!
You need to use VBA:
Sub Range_Copy_Examples()
Worksheets("Car Search").Range("B3").Copy Worksheets("Raw Data").Range("=OFFSET(Sheet3!B1,0,0,COUNTA(B1:B300)+1,1)")
End Sub
However there is a small bug where it keeps pasting across past values, so I have suggested an alternative macro below
Re-edit:
A more mechanical way to make macro work (hopefully someone can improve on it) looks like this:
Sub Macro1()
Sheets("Car Search").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Raw Data").Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Worksheets("Car Search").Activate
End Sub
This works as follows:
in Car Search, have cell B3 selected the whole time
in Raw Data, select the cell with the last value in the column where you want you Car Search!B3 data pasted (you only have to do this once)
press Run on the macro (easy enough to just record one yourself)
go back to Car Search and change the value of B3, press Ctrl-Enter to keep the same cell selected after changing value, then press the same macro button without changing a thing.
If someone could add so that when pressing Ctrl-Enter on Car Search!B3 the Raw Data gets automatically added without having to manually run the macro, it would be fully automated!
I am trying to copy a row of data from one sheet to another having run some other macros, however I keep getting the error message that the paste area and copy area are not the same size and shape.
I have tried using special cells paste method but it seems be missing the data from the last 9 columns.
Code:
id.EntireRow.SpecialCells(xlCellTypeConstants).Copy
missingdata.Range("A" & Rows.Count).End(xlUp).Offset(1,1).PasteSpecial xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
I need help changing the code so it copies the full row of data and pastes it under existing entries in missingdata.
It seems when it works when I choose to paste in Column A, however it does not allow me to paste from column B
I normally use:
Rows(index).Copy
Cells(1,Rows.Count+1).Select
ActiveSheet.Paste
I have created a pivot table to summarize some information and have added some formulas adjacent to the pivot table to do calculations on the numbers included in it. I have created a macro that re-enters the formulas whenever the user changes the size of the pivot table (in the PivotTableUpdate event) by showing or hiding various rows/columns of data.
My problem is that whenever columns of data are added to the pivot table, it asks me "Do you want to replace the contents of the destination cells?" I always click yes, because although the cells will be overwritten when the pivot table expands, the formulas will be re-entered in their correct cell and everything is fixed and formatted properly by the macro.
Therefore, I would like to know where I should put application.displayalerts = false so that it is effective to suppress the message box whenever the user expands the pivot table.
Hi tlewis3348 i think this is what you are looking for
Sub UpdateIt()
Dim iP As Integer
Application.DisplayAlerts = False
For iP = 1 To ActiveSheet.PivotTables.Count
ActiveSheet.PivotTables(iP).RefreshTable
Next
Application.DisplayAlerts = True
End Sub
FWIW This solution worked great for me. I just activated each sheet individually and called the UpdateIt function before doing anything else, e.g.,
Worksheets("RFS Monthly Summary").Activate
UpdateIt
Worksheets("RFS Daily Activity").Activate
UpdateIt
I'm sorry I have no code - I did some research and couldn't find what I wanted.
I have a table that I want to add rows to with the click of a button.
I created a cell at the bottom which says "End".
I want VBA to copy cells from N15:S16 (two rows), and insert two rows above the "End" cell, along with the pasted data.
How would I go about that in a click function?
Just curious whether you realise you may not need any code (or formula) for what appears to be your objective (but wanted to post an image so 'as an answer' regardless).
{In my case using Excel 2007}
Ensure N14:S15 is a Table. (Select N14:S15, Insert > Tables > Table, do not check My table has headers {unless required} and OK).
In Sheet Before I added Table labels and a Total row, in which I added "End" {there is no need for "End"} and added formulae to sum Qty and Value.
With Before as a starting point:
After is the result of selecting N14:S15 and pasting that into N16.
#John Bustos helped me solve it. I recorded a few macros, and this is the code I have now:
Sub Insert_Row_Click()
Range("T15:AK16").Select
Selection.Copy
Application.Goto Reference:="EndCell2"
Selection.Insert Shift:=xlDown
End Sub
Have a nice day everyone!
I have data from like A1:Z50 but I want to delete only A5:X50 using VBA
(I think it will be a lot faster than dragging the whole cell or using clickA5+shift+clickX50+delete).
How can I do this ?
And then, how to lock the cell to prevent it from getting fixed or cleared ?
You could define a macro containing the following code:
Sub DeleteA5X50()
Range("A5:X50").Select
Selection.ClearContents
end sub
Running the macro would select the range A5:x50 on the active worksheet and clear all the contents of the cells within that range.
To leave your formulas intact use the following instead:
Sub DeleteA5X50()
Range("A5:X50").Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Selection.ClearContents
end sub
This will first select the overall range of cells you are interested in clearing the contents from and will then further limit the selection to only include cells which contain what excel considers to be 'Constants.'
You can do this manually in excel by selecting the range of cells, hitting 'f5' to bring up the 'Go To' dialog box and then clicking on the 'Special' button and choosing the 'Constants' option and clicking 'Ok'.
Try this
Sheets("your sheetname").range("A5:X50").Value = ""
You can also use
ActiveSheet.range
Not sure its faster with VBA - the fastest way to do it in the normal Excel programm would be:
Ctrl-G
A1:X50 Enter
Delete
Unless you have to do this very often, entering and then triggering the VBAcode is more effort.
And in case you only want to delete formulas or values, you can insert Ctrl-G, Alt-S to select Goto Special and here select Formulas or Values.