I can't seem to figure out what is wrong with my code. I am trying to set the maximum of a row to a variable lMax. This variable is declared earlier by "Dim lMax".
I try running the code and get the error: "Run=time error '1004': Method 'Cells' of object '_Global' failed. The code that fails is as follows:
lMax = Application.WorksheetFunction.Max( _
Worksheets("Data").Range(Cells(Selected_Row, 7), Cells(Selected_Row, 14).End(xlToRight))) 'Max value
The variable Selected_Row is the row the active row that the user was last on. It is a Global Long variable and was declared in the beginning of the module.
Please help! Thank you!
Related
I'm trying to find the location of a specific string in vba.
The following code gives me the error: Run-time error 91: Object Variable or with block variable not set.
With Range("A2:A62")
Position = .Find("Unplanned").Address
End With
So I tried setting the variable with the following code which gave me the error: compile error type mismatch
With Range("A2:A62")
Dim Position As Range
Set Position = .Find("Unplanned").Address
End With
So then I randomly tried this which gave me compile error:object required
With Range("A2:A62")
Set Position = .Find("Unplanned ").Address
End With
Is there a certain type I should be using or way of writing this that would work better? - I'm very new and self taught with VBA.
I am trying to delete Column A,B,D,E,F,W,X,Y,Z,AA,AB of the sheet FeuilleFP21.
In order to do this I use as seen here and here:
FeuilleFP21.Range("A:B,D:F,W:AB").Delete
But it gives me the following error :
Execution error '1004': The 'Range' method of the '_Worksheet' object
failed.
NOTE : FeuilleFP21 is set like that and in Execution window return the name of the sheet when I use ? ?FeuilleFP21.Name
Set FeuilleFP21 = ClasseurFp21.Worksheets(1)
What am I doing wrong ?
System settings may cause the error. Try separating the columns with ; or whatevery you may have as a "List separator" on your system.
My code pastes a shape onto Sheet1 and tries to resize the width, getting an error on this line below.
Worksheets("Global Quarterly").Shapes(Picture1).Width = 1607.76
GlobalFile.Activate
Sheets("Sheet1").Select
ActiveSheet.Paste Destination:=Range("B25")
Selection.Name = "Picture1"
Worksheets("Global Quarterly").Shapes(Picture1).Width = 1607.76
Range("A1").Select
Application.ScreenUpdating = False
Option Explicit is likely missing, making Picture1 an undeclared variable, so at run-time you're passing Variant/Empty to the Worksheet.Shapes collection's Item property getter - and that's neither an index nor the name of a shape, so you get a... well an arguably confusing run-time error: a more instinctive error to throw would have been error 5 here, for "invalid parameter or procedure call" - it's the Shapes.Item member (implicit) that's throwing; execution never even gets to the Shape.Width member call.
Specify Option Explicit at the top of every module; that will make your code uncompilable until all variables are declared, which helps prevent typos and forces a minimal rigor in variable usage.
If the name of the shape is "Picture1" (note the string delimiters / double-quotes), then you need to do as Lodi hinted:
Worksheets("Global Quarterly").Shapes("Picture1").Width = 1607.76
I named a column: DailyReserveCol
Created simple Hide/Reveal column button
Sheets("Calculator").Columns.DailyReserveCol.Hidden = Not Column.DailyReserveCol.Hidden
But I receive the following error:
Run-time Error 424 Object Required
This works:
Sheets("Calculator").Columns("C").Hidden = Not Columns("C").Hidden
I've tried:
Columns(DailyReserveCol).Hidden
Columns("DailyReserveCol").Hidden
Error 13 Type mismatch
Am I doing it incorrectly or is this not possible?
You can use the following to toggle the visibility of a named column:
Sheets("Calculator").Range("DailyReserveCol").EntireColumn.Hidden = _
Not Sheets("Calculator").Range("DailyReserveCol").EntireColumn.Hidden
The code below has worked until my most recent update to it in. It still does work, but for some reason, it errors when opening it on a new PC if you have to click Enabling Editing. If you Enable Editing, end the routine, and close the spreadsheet, it works from there. I am just trying to understand what might be causing the hiccup on the initial open after Enabling Editing.
The code (please note that "Mnger_Tags" is a named group defined in the spreadsheet):
Dim Mnger As Variant, MngerCheck As String
Application.DisplayAlerts = False
'Determine User/Manager
Mnger = Application.Transpose(Range("Mnger_Tags").Value)
MngerCheck = LCase(Environ("UserName"))
If IsInArray(MngerCheck, Mnger) Then
frmMngerCheck.Show
MngerCheck = frmMngerCheck.MngerCheck
Unload frmMngerCheck
End If
The Error:
Takes place on line "Mnger = Application.Transpose(Range("Mnger_Tags").Value)"
Run-time error '1004':
Method 'Range' of object '_Global' failed
The goal:
The first line of code is meant to take whatever names are listed in that named range (Mnger_Tags) and create the array Mnger.
The code will then check if any value in the array Mnger match the UserName (MngerCheck).
I hope this is clear enough. This is my first post. Thank you all in advance.