Edit Code From The Macro Recorder
Jul 25, 2006
The way i have been creating macros is by going to the tools menu.....macro....then..... record new macro.
I have a file which I have re-formatted using a macro as described above however because i receives files every month to do updates every time i open a new file and try to perform that same macro it either wont work or it wont format the correct rows.......is VBA the solution to this????
View 9 Replies
ADVERTISEMENT
Sep 9, 2007
What is the most efficient VBA code for the following macro recorded codes? I wish to write more efficient code versus the lengthy, cumbersome macro recorder code.
1) Macro Recorder Code to Copy One Sheet to Another
Sheets("Data Apple").Select
Cells.Select
Selection.Copy
Sheets("Banana").Select
Cells.Select
ActiveSheet.Paste
2) Macro Recorder Code for Replacement Purposes......................
View 9 Replies
View Related
Apr 1, 2008
I need a code to change the Macro security settings of the computer where the file is opened to enable macros.
View 9 Replies
View Related
Jun 9, 2009
I hide all Excel standard tabs and thus need a button on custom tab to record a macro. (I did this successfully with custom menu in Excel 2003.) In 2007 ribbon, I've reused the code for a button's OnAction, now going to callback that runs:
Application.CommandBars.ExecuteMso ("MacroRecord")
In Excel 2003, the stop button appeared automatically for me. But in Excel 2007, with hiding standard tabs, etc., I see no way to stop recording, other than running my button to return the Developer's tab, where the Record Macro button has changed to Stop Macro.
I'd like to either add a second button to my ribbon to stop recording the macro (but I can't find an idMso to use in a callback) or have my Record button change to Stop button, like Excel does. But I can't come up with correct code.
View 4 Replies
View Related
Jun 10, 2009
I used macro recorder, and this code was the result. Is there a way to shorten this code up? The more I use macro recorder, the more I'm beginning to realize that the code generated from macro recorder can be very sloppy.
View 8 Replies
View Related
Jul 7, 2009
Have recorded a Macro which is doing a great job, but when i try to run the same macro from other pc its not running,pops an search error.
View 9 Replies
View Related
Jun 22, 2006
Is it possible to use the Macro recorder in Excel to store user variables that they put in through a UserForm? So say when a textbox on a userform is changed, it records a macro of what is put into the textbox, which it can then call to retrieve the value.
View 4 Replies
View Related
Sep 30, 2008
I used the macro recorder to create a pivot table, but to verfity that it works.
I get a "Add fields method of Pivot Table class failed"..
and this was highlighted:
ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:=Array("Warehouse" _
, "Product", "Description", "Data")
View 9 Replies
View Related
Aug 24, 2007
I have recorded a simple macro ( copying a cell, and then pasting the formula into various others), and I get the following error
Compile Error: Argument Not Optional
I have highlighted where the error first happens
Sub Macro3()
'
' Macro3 Macro
' Macro recorded 24/08/2007 by Michael Traynor
'
'
Range("K7:K8").Select
Selection.Copy
Range("K167:AJ168").Select
Range("AJ167").Activate
Range("K167:AJ168,K175:AJ176").Select
Range("AJ175").Activate
Range("K167:AJ168,K175:AJ176,K183:AJ184").Select
Range("AJ183").Activate
Range("K167:AJ168,K175:AJ176,K183:AJ184,K191:AJ192").Select
As I've said I didn't write this, it was recorded from Excel.
View 7 Replies
View Related
Sep 4, 2007
I've created VBA code in Access 2007 to create a column chart in Excel, and it is working. I need to change the rotation on my category labels to 270 degrees vertical. When I record a macro on the chart in Excel 2007. I only receive the following
Sub chartingRotation()
'
' chartingRotation Macro
'
'
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Axes(xlCategory).Select
ActiveSheet.ChartObjects("Chart 1").Activate
End Sub
How can I get the macro recorder to record changes to chart properties?
View 4 Replies
View Related
Oct 11, 2012
I have used the macro recorder to generate the select range and clear part of the following macro.
Private Sub CommandButton2_Click()
Dim test As Worksheet
Sheets("Industry").Copy After:=Sheets(Sheets.Count)
[Code]....
I get the runtime error 1004 - Select method of range class failed.
I have used similar script in other macros without error.
View 2 Replies
View Related
Dec 6, 2013
Had 2003 now 2013. Trying to get the macro to select different printers for different doccuments. 2013 macro recorder does not record any printer info or path, all printers show the same wording just application print...
How can I get the recorder to acurrately record and diferentiate printers?
View 2 Replies
View Related
Oct 11, 2011
I am using office 2011 for MAC, and am trying to create a macro that changes the color of the selected cell(s).
if I start recording the macro
click the fill color button pull down and change the color on the edit section of the ribbon
Stop the macro
No code is recorded as below but the cell did change color to whatever I selected.
Sub Macro13()
'
' Macro13 Macro
'
'
End Sub
[code].....
The colorIndex is automatic no matter what color I choose.
When I run the macro there is no change to the selected cell, but the border is destroyed.
View 2 Replies
View Related
Jun 3, 2009
Right now i have two worksheets:
"900 - Reel"
"OverRides"
On the "900 - Reel" sheet i have a userform ("userform4") open when double clicking a specific cell. Upon opening it uses the following code to go to sheet "OverRides" to find two specific values and imputs them into "textbox1" and "textbox2" on "userform4"
View 4 Replies
View Related
Jan 5, 2007
I have a list of worksheet names in a combobox, when selected using the drop down arrow it takes you to that worksheet. The problem is say I select "ABC" from the list and it takes me to the "ABC" worksheet but when I go back to the summary page the "ABC" is already selected in the drop down box and I cannot click it any more. Is there anyway to reset the combo box so that it goes back to the first selection of the list?
Private Sub AFISGBox_Change()
Dim strSheet As String
If AFISGBox.ListIndex > -1 Then
strSheet = AFISGBox
Sheets(strSheet).Select
End If
End Sub
View 9 Replies
View Related
Jul 21, 2006
Is it possible to enable the undo command when using VBA code in a spreadsheet? Right now if someone makes a mistake it can’t be undone.
View 5 Replies
View Related
Feb 22, 2008
How do I make this formula include searching for "ann" and "john" (in separate cells)?
View 2 Replies
View Related
Jun 24, 2014
I'm working on a mac and have a macro that will go through all the sheets in my workbook and save them as PDFs to a specific location.
Sub CreatePDF()
For sh = 19 To Sheets.Count
Sheets(sh).ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"/Users/mikemahoney/Desktop/Publisher Payables/Statements/June 2014" & Sheets(sh).Name & "June 2014 Revenue Share Statement" & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
Next
End Sub
The part in bold is obviously where I am saving the PDFs but it is also being included in the naming of the file. Need replacing the red text in the naming of the file with the contents of cell B9? I would still like to save the PDF to "/Users/mikemahoney/Desktop/Publisher Payables/Statements/June 2014" I just don't want the file-path to be included in the name of the file.
Also, this code seems to run into errors if a sheet is hidden, hence starting at sheet 19. Any way to tweak this code to skip over hidden sheets?
View 1 Replies
View Related
Oct 13, 2008
I just wonder if we can have the code to exit if G2 returns an even number, as 2, 4, 6 etc?
Sub Listbox3_Change()
If ActiveSheet.Index 1 Then Exit Sub
Application.ScreenUpdating = False
With Sheets(1)
.Unprotect "mypsw"
.Range("G2").Value = ActiveSheet.ListBoxes(Application.Caller).Value
With .ChartObjects("Chart 2").Chart.Axes(xlValue)
If VBA.VarType(Sheets(1).Range("D1").Value) = VBA.vbError Then Exit Sub
If VBA.VarType(Sheets(1).Range("E1").Value) = VBA.vbError Then Exit Sub
.MinimumScale = (Sheets(1).Range("D1") - 0)..............
View 9 Replies
View Related
May 28, 2013
below is the code i use to create a lotus note email.
i would like it to display my email and send it manually instead of sending out automatically.
' Open and locate current LOTUS NOTES User
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
[Code].....
View 4 Replies
View Related
Aug 15, 2007
When I list my macros using alt+F8 the edit option is no longer available, any ideas what I have done?
View 9 Replies
View Related
Feb 21, 2007
I have recorded a macro that will copy and paste information from text files to two separate sheets in a workbook. Previous versions of this have worked fine but now I have a "subscript out of range problem" for this line: Sheets("Raakadata").Select
I'm doing this project to someone else and the weird thing is I don't see this error in my computer but they have it in theirs. The workbook has been recently renamed to oljy_vedesta.xls but it should be correct in the code. The syntax should be fine as macro recorder has been used but still this error comes up with the another computer (all the required files are there).
Sub Tulosten_haku()
ChDir "C:Makro"
Workbooks.OpenText FileName:="C:MakroOLJY_VEDESTA_QC.TXT", Origin:= _
xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=True, _
Comma:=False, Space:=False, Other:=False, FieldInfo:= Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1))
Workbooks.OpenText FileName:="C:MakroOLJY_VEDESTA.TXT", Origin:=xlWindows _
, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=True, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), _
Array(3, 1), Array(4, 1), Array(5, 1))..........................
View 2 Replies
View Related
Feb 4, 2008
I have a macro that allows me to type numbers in cells and it auto adds to the previous value... what would be nice is if when i hit enter the cell focus stays at the current cell and doesnt move the next cell down... that way if i wanted to enter multiple values into one cell i wouldnt have to touch the arrow keys to get back to the cell
e.g: i enter a value into A1 and hit enter, instead of the box focus moving to A2, it stays at A1
Heres my current
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("DATA")) Is Nothing Then Exit Sub
If Target.Cells.Count > 1 Then Exit Sub
If Not IsNumeric(Target.Value) Then Exit Sub
Application.EnableEvents = False
Target.Value = Target.Value + oldVal
Application.EnableEvents = True
End Sub
View 9 Replies
View Related
Mar 3, 2007
Sub Delete_0_Rows()
'Assumes the list has a heading.
Dim i As Integer
For i = Cells(65536, 1).End(xlUp).Row To 5 Step -1
If Cells(i, 1) = "0" Then
Range(Cells(i, 1), Cells(i, 1).Offset(-2, 0)).EntireRow.Delete
End If
Next
End Sub
I have data in the first 50 rows.
Then in row 51 it column A it starts 0's.
I run the macro, it deletes all the rows with 0's, and it deletes row 50 also some reason. I do not understand the above macro very good to edit it, and the fact it contains 5 1's doesnt help me lol
View 9 Replies
View Related
Jul 24, 2007
I cannot run code from the formula bar.
I have a context sensitive menu
Sub AddContextMenu()
On Error Resume Next
Application. CommandBars("formula bar").FindControl(msoControlButton, 0, "MYMENU").Delete
On Error Goto 0
Dim objTemp As CommandBarButton
With Application.CommandBars("formula bar")
Set objTemp = .Controls.Add(msoControlButton, , , .Controls.Count + 1, True)
With objTemp
.Caption = "Formula Menu"
.BeginGroup = True
.OnAction = "TestMe"
.Tag = "MYMENU"
End With............
View 9 Replies
View Related
Jun 18, 2009
I have disabled edit directly in cell in the option menu so that when i double click it goes to source file.
View 3 Replies
View Related
Dec 7, 2007
I was wondering if it was possible for a macro to edit a file by opening each .txt file, searching for the word "Reference", and then replace it with the word "Ref". Then save and close the text file.
There are no delimiters in the text files.
View 9 Replies
View Related
Jan 27, 2012
I have an array formula i use to sum data by specific criteria:
=SUM(IF(Input_Sheet!$A$2:$A$1000>
=DATEVALUE("01/04/2011"),IF(Input_Sheet!$A$2:$A$1000
=DATEVALUE("??/??/????")
So that it searches for any date and replaces with the new ones, but obviously the use of quotation marks with the wildcards makes this difficult in VBA.
How to link the cell values in with the "Replace with".
Code:
Sub findrep()
Dim target, cell As Range
Dim i As String
Dim k As String
i = "Input_Sheet!$A$2:$A$1000>=DATEVALUE("??/??/????")"
[Code]....
View 3 Replies
View Related
Mar 19, 2012
How would my macro below be edited to keep the column sizes the same as they are in the original sheet?
Sub NewUploadFile()
Workbooks.Add
ThisWorkbook.Worksheets(3).Range("A2:K300").Copy
Range("A3").PasteSpecial Paste:=xlPasteValues
Range("A3").PasteSpecial Paste:=xlPasteFormats
Columns.AutoFit
End Sub
View 7 Replies
View Related
Oct 29, 2012
how to control either the X or Y axis error bars for a scatter chart.
I'm building something like a gantt chart and I only want to use the X axis error bars and delete the Y axis bars. I've been able to add error bars by using "ActiveChart.SeriesCollection(1).HasErrorBars = True" but when i select the error bars using "ActiveChart.SeriesCollection(1).ErrorBars.Select" the Y axis (Vertical Error Bars) are automatically selected and any formatting I apply is added to the Y axis and left off of the X axis.
Does anyone know how to delete the Y axis error bars and/or choose only the X axis error bars?
View 5 Replies
View Related