When I try to record a macro doing a Vlookup from another sheet, a 1004 error message appears and shows a problem with the first line of the code created.
The error is in the first line:
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-6],'[Suppliers and their bank accounts.xlsx]Sheet1'!C1:C2,2,0)"
Sub Macro4()
'
' Macro4 Macro
'
'
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-6],'[Suppliers and their bank accounts.xlsx]Sheet1'!C1:C2,2,0)"
ActiveSheet.Range("$A$1:$L$431").AutoFilter Field:=3, Criteria1:="="
Range("B2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 6).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
Selection.FillDown
Selection.End(xlUp).Select
ActiveSheet.Range("$A$1:$L$431").AutoFilter Field:=3
End Sub
Related
I recorded a macro to create a button that would filter my contracts to find only the ones with a - in them and copy and paste them into another sheet and got this:
Sub Contracts_Hyphen()
'
' Contracts_Hyphen Macro
'
'
Sheets("Transactions").Select
ActiveSheet.Range("$A$1:$AA$31579").AutoFilter Field:=5, Criteria1:=Array( _
"17030-89", "39975-41468-43641-45775-48215-49324", "40011-41747-46077", _
"43642-45773", "43773-46237", "46078-46771", "46238-46409"), Operator:= _
xlFilterValues
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Contracts").Select
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.AutoFilter
Range("A1").Select
End Sub
The problem with this code is that if I added another contract with the number for example "18936-87645" this macro would not find it. So what I changed it to was:
Sub Contracts_Hyphen()
'
' Contracts_Hyphen Macro
'
'
Sheets("Transactions").Select
ActiveSheet.Range("$A$1:$AA$31579").AutoFilter Field:=5, Criteria1:="-"
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Contracts").Select
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.AutoFilter
Range("A1").Select
End Sub
But now with that change it is not finding anything. So how can I setup my macro to include numbers with hyphens even potentially newly added numbers?
I have a list that has names and I have recorded a macro to help me copy, paste, format and move to next names in list. It is working, however something crucial is missing because the macro does not keep the previously recorded data, and it does not move to next names in list.
I ran the macro of different rows and tried recording the macro again but it is not working as expected
Sub Accrual()
'
' Accrual Macro
'
'
ActiveSheet.Range("$A$1:$G$1007").AutoFilter Field:=1, Criteria1:= _
"doe, john"
Range("A2").Select
Selection.Copy
Sheets("Sheet4").Select
Range("A2").Select
ActiveSheet.Paste
Sheets("Sheet3").Select
Range("B2:C2").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet4").Select
Range("C2").Select
ActiveSheet.Paste
Range("E2").Select
Sheets("Sheet3").Select
Range("F2:F6").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet4").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Range("A3").Select
End Sub
I would expect my recorded macro to go down my list of names and copy, paste, and format all the names in the list and keep all the data
I have the following code that arranges data from "Sheet1" in multiple workbooks that are located (saved) in a folder named "TestVerificari". The following code (attached) works grate, but I have to run-it manually for every workbook. Is there a way to insert this code in a loop and run-it a single time for all workbooks saved in that folder? Thank you very much!
Sub VerificariCE()
'
' Macro1 Macro
'
'
Rows("1:5").Select
Selection.Delete Shift:=xlUp
Columns("A:D").Select
Selection.Delete Shift:=xlToLeft
Range("A1:B50000").UnMerge
Columns(2).Delete
Selection.UnMerge
Columns("B:B").Select
Columns("C:D").Select
Range("C50000").Activate
Selection.Delete Shift:=xlToLeft
'''''''''''''''''''''''''''''''''''
Range("D1").Select
Selection.Copy
Range("G1").Select
ActiveSheet.Paste
Range("G2").Select
ActiveCell.FormulaR1C1 = _
"=TRIM(MID(SUBSTITUTE(RC[-2], """""""", REPT("" "", 999)), 2999, 999))"
Range("G2").Select
Selection.AutoFill Destination:=Range("G2:G50000")
Range("G2:G50000").Select
Columns("B:B").EntireColumn.AutoFit
Columns("A:A").EntireColumn.AutoFit
Columns("G:G").EntireColumn.AutoFit
Selection.AutoFilter
ActiveSheet.Range("$A$1:$M$50000").AutoFilter Field:=1,
Criteria1:=Array( _
"AutorizareExport", "CautarePF", "CautarePJ",
"DescarcaRaportClient", _
"GenereazaRaportClient", "InapoiLaCautare", "InrolareClientNouPF", _
"IstoricDocumente", "Meniu_DocumentReport",
"ModificareDateClientPF", _
"ModificareDateClientPJ", "ModificarePFInitiativaBancii",
"PaginaCautare", "="), _
Operator:=xlFilterValues
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
End Sub
I need a macro to append a comma onto the beginning of a column of text strings. I recorded the action myself, but it limited itself to Column C (often, the text strings I need to do this with appear in a different column), and also limited the application of the range to the specific number of rows in the worksheet I recorded it on (in this case, 114).
Here is the original Record Macro output:
Sub AddCommaToESIID()
'
' AddCommaToESIID Macro
'
'
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("E:E").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("C2").Select
ActiveCell.FormulaR1C1 = ","
Range("C2").Select
Selection.AutoFill Destination:=Range("C2:C114")
Range("C2:C114").Select
Range("E2").Select
ActiveCell.FormulaR1C1 = "=RC[-2]&RC[-1]"
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E114")
Range("E2:E114").Select
Selection.Copy
Range("D2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Columns("E:E").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Columns("C:C").Select
Selection.Delete Shift:=xlToLeft
End Sub
I would like to modify this to achieve the following:
Make the macro apply to whatever Column I have selected, as opposed to Column C
Once I have selected a Column, make the macro apply to however many rows there are in the particular worksheet I'm working on.
Thanks in advance for your help!
This will change all non-formulas in whatever range you select
Sub AddCommaToESIID()
Dim rCell As Range
If TypeName(Selection) = "Range" Then
For Each rCell In Selection.Cells
If Not rCell.HasFormula Then
rCell.Value = "," & rCell.Value
End If
Next rCell
End If
End Sub
I'm using the following VBA code to automate moving a row on one sheet to another. About 1/3 of the time, it gives a "run-time error '-2147417848 (80010108)" and then crashes Excel. I cannot find a common reason why. After a crash, I can execute the same code on the same row, and it may or may not work fine the next time.
Can anyone tell why this code below should be unstable?
Sub Move_to_Sheet2 ()
'
' Move_to_Sheet2 Macro
'
' Keyboard Shortcut: Ctrl+r
'
Rows(ActiveCell.Row).Select
Selection.Copy
Set Rng = Nothing
Sheets("Sheet2").Select
Rows("4:4").Select
Selection.Insert Shift:=xlDown
Sheets("Sheet1").Select
Selection.Delete Shift:=xlUp
ActiveWorkbook.save
End Sub
You need to fully qualify your Rows. See this example.
Sub Move_to_Sheet2()
Dim ws As Worksheet
'~~> Change this to the relevant sheet name
Set ws = Sheets("Sheet1")
With ws
.Rows(ActiveCell.Row).Copy
Sheets("Sheet2").Rows("4:4").Insert Shift:=xlDown
.Rows(ActiveCell.Row).Delete
End With
ActiveWorkbook.Save
End Sub
Sub Test()
' Test Macro
Range("A24:C30").Select
Selection.Copy
ActiveWindow.ScrollRow = 4
ActiveWindow.ScrollRow = 5
ActiveWindow.ScrollRow = 6
ActiveWindow.ScrollRow = 7
ActiveWindow.ScrollRow = 9
ActiveWindow.ScrollRow = 10
Range("A31").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Copy
Sheets("Save Sales").Select
Range("B6").Select
Selection.Insert Shift:=xlDown
Sheets("Invoice").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = ""
Range("B9").Select
MsgBox "Print Now"
End Sub