Inputbox Method NOT Returning Multi-cell Range Object
Jun 15, 2012
I have the following code in Destination.xlsm that is intended to:
request the user to select a multi-cell range in a column of single-sheet Source.xlsm, in which some but not all cells contain "Y" (to indicate that this row of data relates to a National Account, versus a Territory Account)loop through the selected range, and whenever a cell contains "Y", copy the entire row and insert it in Destination.xlsm above a cell named "rngDest".
Code:
Sub Copy_NationalAccounts_Rows()
Const Message As String = "Select the entire range containing National Account Y flags, then press Enter or click OK."
Const Title As String = "Copy National Accounts"
Dim rngSource As Range
Dim rngDest As Range
Dim r As Range
Dim c As Integer
Dim wbk As Workbook
[Code] ........
View 5 Replies
ADVERTISEMENT
Aug 23, 2006
How do I add multiple worksheets at once after opening a new workbook? I was able to go to Insert>Workbook but it only adds one sheet at a time. I I need to add 50 woorksheets, I don't want to really click 50 times.
Insert a new worksheet
To add a single worksheet, click Worksheet on the Insert menu.
To add multiple worksheets, hold down SHIFT, and then click the number of worksheet tabs you want to add in the open workbook. Then click Worksheet on the Insert menu.
When I hold down the shift button and enter 50 i get the "%" and ) sign entered on the open workbook and then I try to click worksheet from the insert tab and it is greyed out.
View 4 Replies
View Related
Dec 10, 2008
I'm trying to get the Find and FindNext methods to work. Column C contains serial numbers and there's a chance that a serial number might appear more than once in the column. What I'm trying to do is get Excel to find the first occurance of the serial number, find what row it's on and then see if this matches the variable 'CurRowNo' (defined earlier in the code). If it doesn't I want it to look at the other occurances of the serial number, find what row they're on and see again if it matches CurRowNo.
The variable 'EngCount is the number of occurances of the serial number (also worked out earlier in the code). I've got the code below, but I get the error 'Method Range of Object Global Failed' on the FindNext line. I have no idea what this error means or why it's happening.
View 3 Replies
View Related
Jun 23, 2006
Using InputBox Method to Select Range from Other Sheets
I need to select a range of cells from a second workbook via a InputBox or similar.
I'm trying to do that with the following
Sub InputBoxTest()
Dim MySelection As Range
Set MySelection = Application.InputBox(prompt:="Select a range of cells", Type:=8)
MySelection.Select
End Sub
But I can't select a cell range if it is located in other workbook.
View 5 Replies
View Related
Jan 6, 2010
I'm trying to select a range that will be changing by column. I'm not sure why my syntax isn't working. What I've got:
View 2 Replies
View Related
Jan 24, 2009
I have a while loop in which I'm updated information in 2 separate worksheets. I'm using the With-block statements separately to update each, but after the 30th iteration (and it's always on the 30th), the VBA code halts and get the "method 'value' of object 'range' failed" error message pointing to a line with the code as follows:
With Sheet1
.Cells(lngRow, 9).Value = intMonths
End With
where "intMonths" is an integer variable which I'm populated properly, and "lngRow" a long variable. When I debug both variables have proper data in them, and I have no idea why this is bombing.
View 9 Replies
View Related
Jun 23, 2009
I can't seem to figure out why this keeps giving me that error...
I've checked the row and column values inside and they seem to be ok. blank_ee() is an array of strings.
View 7 Replies
View Related
Sep 10, 2006
Sub a()
z = 4
y = 7
sWork. Range(Cells(1 + nRow(z), 4), Cells(1 + nRow(z), 12)).Replace y, 0 lookat:=xlPart, searchorder:=xlByRows, MatchCase:=False
End Sub
but when I include it in my main code
sWork.[A1:L9] = 123456789
For z = 1 To 81
y = [A1].Offset(nRow(z), nCol(z))
If y > 0 Then
sWork.Cells(1 + nRow(z), 1).Replace y, 0, lookat:=xlPart,searchorder:=xlByRows, MatchCase:=False, matchbyte:=False
sWork.Cells(1 + nCol(z), 2).Replace y, 0, lookat:=xlPart, searchorder:=xlByRows, MatchCase:=False, matchbyte:=False
sWork.Cells(1 + nBox(z), 3).Replace y, 0, lookat:=xlPart, searchorder:=xlByRows, MatchCase:=False, matchbyte:=False
sWork.[A1].Offset(nRow(z), nCol(z) + 3).Value = 0
sWork.Range(Cells(1 + nRow(z), 4), Cells(1 + nRow(z), 12)).Replace y, 0, lookat:=xlPart, searchorder:=xlByRows, MatchCase:=False
sWork.Range(Cells(1, 4 + nCol(z)), Cells(9, 4 + nCol(z))).Replace y, 0, lookat:=xlPart, searchorder:=xlByColumns, MatchCase:=False
sWork.Range(Cells(1 + Int(nRow(z) / 3) * 3, 4 + Int(nCol(z) / 3) * 3), Cells(3 + Int(nRow(z) / 3) * 3, 6 + Int(nCol(z) / 3) * 3)).Replace y, 0, lookat:=xlPart, searchorder:=xlByRows, MatchCase:=False
End If
Next
I get a "Method 'Range' of object '_Worksheet' failed" error at line 9,
when z = 4, y = 7, and nRow(z) is a UDF which = 0.
View 8 Replies
View Related
Nov 8, 2006
I have a button on my spreadsheet which activates some code, it has worked perfectly for over a year but now for some reason I cannot get it to work.
When I click on the button now I get the message: Run-time error '1004' Method ' Range' of object '_Global' failed.
the file is far too large to attach here but here is the relevant ...
View 8 Replies
View Related
Apr 26, 2007
I'm trying to accomplish the following: on "LogSheet" sheet, click on the DailyCloseButton and have various lists on the "lists" sheet automatically sorted before I save and end. The code below gives an error: "Method ' Range' of object '_Worksheet' failed". I have no idea why it failed.
Private Sub DailyCloseButton_Click()
' DailyClose and sort routine
'Sort lists
Sheets("Lists").Activate
Range("Products").Select
Range("Products").Sort Key1:=Range("Products").Cells(2, 1), _
Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal.............
View 9 Replies
View Related
Jul 6, 2007
I am having a problem with this bit of code. When I try to run it it shows Method Range of object Worksheet Failed.
The original code I adapted this from works just fine, and the only thing I have changed is the ranges and the sheet.
The code is:
Sub Filter()
With Sheet18
'
.Range("DisbData").AdvancedFilter Action:=xlFilterInPlace, _
CriteriaRange:=.Range("Criteria"), Unique:=False
.Range("DisbData").SpecialCells(xlCellTypeVisible).Copy Destination:="DisbPaste"
.ShowAllData
End With
End Sub
The line that the debugger is showing has issues is:
.Range("DisbData").AdvancedFilter Action:=xlFilterInPlace, _
CriteriaRange:=.Range("Criteria"), Unique:=False
View 4 Replies
View Related
May 2, 2009
I'm trying to set the print area on two sheets in the same workbook and it is returning Method 'Range' of object' _Global failed error every time and I can't figure out what code to change to make this error stop happening. here is my
View 5 Replies
View Related
May 20, 2008
I start in my "Action Plan for For Single Market" worksheet and if I click on the Command Button I then want to read in a couple of variables, and jump to a second worksheet (called "Market Action Plans") where I then want to copy a range, and then paste it in another area in that same sheet.
I thought I had worked out what to do, but when I execute I get a "run-time error 1004" when the macro gets to the "Range("Updated_Results").Copy" line. Excel describes the error as "Method 'Range' of object '_Worksheet' failed'" - which might as well be a foreign language as far as I am concerned!
Private Sub CommandButton2_Click()
Current_Market_Row = Range("Current_Market_Row")
First_Col_Action_Desc = Range("First_Col_Action_Desc")
Sheets("Market Action Plans").Select
Range("Updated_Results").Copy
Cells(Current_Market_Row, First_Col_Action_Desc).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Action Plan for Single Market").Select
End Sub
I am an occasional macro-creator and every now and again, I come across this type of problem where I can't get variables to be reconized, etc. I think it's because I don't understand enough about Private versus Public, and how to declare variables.
View 9 Replies
View Related
Oct 11, 2012
Why am I getting method range of object global failed error message? The error seems to lie in the line highlighted in red.
VB:
[CODE]Private Sub btnEditDelete_Click()
Dim customerID As String
Dim rowID As Integer
Dim foundFlag As Integer
Dim lastrecFlag As Integer
Application.ScreenUpdating = False
[Code] .....
View 4 Replies
View Related
Sep 26, 2009
I'm so new to VBA this is probably another simple question, but here goes...
The error-text is:
"Method 'Range' of object '_Global' failed"
It happens at:
rng = Range(gCSchedule.Ws.Cells(gCSchedule.DateRow, StartCol))
See following code.
View 8 Replies
View Related
Oct 3, 2011
I have written a sub with the purpose of finding rows based on a critieria, copying the rows to another worksheet and deleting the original row.
The code:
Code:
Sub MoveToIgangvaerende()
'
' Flytter opgaven til sheetet Igangværende projekter
'
Dim i, j, Index As Integer
Forfra:
For i = -1 To 1000
If Sheets("Pipeline").Cells(3 + i, 20) = "Ja" Or Sheets("Pipeline").Cells(3 + i, 20) = "ja" Then
[Code] ......
I get the error message "Method 'Delete' of object 'Range' failed" at the line "Sheets("Pipeline").Cells(3 + i, 18).EntireRow.Delete".
The sub has previously worked perfectly fine.
View 4 Replies
View Related
Mar 16, 2009
Method range of object global failed
When i run this ....
View 9 Replies
View Related
Jun 28, 2006
I have a cet of CommandButtons on sheet 1. The code for these buttons is in the code section of the sheet. A named range is referenced in this code. This named range is on sheet 2. Every time I try to reference this or any named range (from any other sheet), I get this "Run-time error '1004': Method 'Range' of object '_Worksheet' failed"
The last time I had this error I was able to fix it by moving the code to Module1. I tried that here, but it did not work (I can't figure out how to call it from the sheet). CommandButton. Here is the code from the sheet for one of the buttons:
Private Sub TBEnterUp_Click()
iLast = Range("WBDate_DayLast").Value '<<<<<<<
iItem = TBEnter.Value
If iItem = iLast Then
TBEnterUp.Visible = False
Exit Sub
End If
TBEnter.Value = iItem + 1
If iItem > 0 Then TBEnterDown.Visible = True
End Sub
It is a simple number advancer. It is working in the UserForm I took it from. I have included a sample file of the problem. Feel free to look at it and borrow anything in it that you might like.
View 2 Replies
View Related
Feb 10, 2009
I am trying to build a macro which will format the columns of a spreadsheet - basically it inserts some columns, writes formulas and highlights them. Here is a code I have got so far...
When I try to run this I get a run time error 1004 - Method 'Range' of 'Object'_Global' failed. The part of the code
Range("N2:N").FormulaR1C1 = "=(RC[-7]/RC[-2])"
is highlighted in the debugger.
Can anyone tell me why this is happening, also it would be great if you could suggest better ways of writing this code - as I am new to vba programming and most of my macros are built using the recorder and then 'working' on them.
View 11 Replies
View Related
Mar 25, 2009
I have an interesting error that only happens when there is one row of data in the worksheet (sheet2 or "Half Payout"). Rows 1 & 2 are headers, row 3 is when the data starts - if any. With either no rows of data or more than one the coding works just fine. Here is the exact error message I'm getting: Run-time error '1004': Method 'Range' of object '_Worksheet' failed.
The following code is supposed to sort the rows of data when opened and then activate the first open cell below B2.
View 6 Replies
View Related
Dec 26, 2008
i'm tring to reuse this code which creates a label on excel. The data used to create the labels is on the "Data" sheet and the labels are generated on the "Label" sheet.
The problem is the first time i run it it generates the labels, then whenever i try again it gives me the following error; Method 'Range' of object '_Global' failed. Each row on the "Data" sheet repreents a label.
View 6 Replies
View Related
Oct 7, 2011
Rows keep changing so I have variables to keep track of various locations.
At this point:
tot_new_place equals 30
tot_new_cnt equals 51
I want to take the data in B30:H30 and copy, auto fill to B51:H51
I am receiving the error on this line of code:
Range("B" & tot_new_place & "").Select
Selection.AutoFill Destination:=Range("R" & tot_new_place & "C2:R" & tot_new_cnt & "C9"), Type:=xlFillDefault
View 9 Replies
View Related
Feb 28, 2013
I M Getting Run Time Error 1004 Method Range Of Object _ Worksheet Failed
Option Explicit
Private Sub cboPart_AfterUpdate()
'On Error Resume Next
[Code]...
View 1 Replies
View Related
Jan 13, 2010
I am trying to create a macro in my personal macro book such that whenever any workbook is opened the calculation settings (tools, options, calculation tab) are set to semiautomatic and do not calculate before save. The macro works when I am opening Excel itself (Book1) but when I open an already saved file it gives me
Run-time error '1004'
Method 'Range' of object'_Global' failed
From there I choose Debug, the VBE window comes up, and I hit F5 to continue the code without doing any actual debugging. Here is the code that I am using. This is in the Personal Macro book on the "This Workbook" section....
View 9 Replies
View Related
Jan 15, 2010
I get an error message on the "Range(lstRow).Select line. (Method 'Range' of Object '_Global' failed). My goal is to transfer a specific range (C24:H24) to the first available row in Data Entry sheet.
View 2 Replies
View Related
Feb 25, 2014
I need a macro to sort on five columns (Column A, L, P, X, and Y) out of about 33 columns. Sort is all lowest to highest.
The code I have so far is:
Sub Macro1()
Range("A2:AG").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("L2") _
, Order2:=xlAscending, Key3:=Range("P2") _
, Order3:=xlAscending, Key4:=Range("X2") _
, Order4:=xlAscending, Key5:=Range("Y2") _
, Order5:=xlAscending
End Sub
However, I get an error "runtime error 1004 - method range of object global failed".
View 1 Replies
View Related
Jan 6, 2009
I have a userform listbox2 that i am trying to save info from to a worksheet.
I am getting the error "Object doesn't support this poperty or method" when I am trying to set the cell of a find ......
View 9 Replies
View Related
May 12, 2006
I am having trouble assigning the range given by an inputbox method to the variable targetcells, and subsequently selecting targetcells. any help would be most appreciated.
Dim i As Integer
Dim CopyCells As Range 'the cells into which links will be copied
Dim TargetCells As Range 'the cells that copycells will be linked to
Dim CopyAddress As Variant 'the address of the copycells
Dim TargetAddress As Variant 'the address of the targetaddress
i = 0
For i = 1 To 100
Set CopyCells = Application.InputBox("Click on the cells to copy", "Automating copying links", Type:=8)
Set TargetCells = Application.InputBox("Select the target cells", "Automating copying links", Type:=8)
TargetCells.Select 'this line doesn't work for some reason (why?)
TargetAddress = ActiveWorkbook.Name 'this and the above lines are the ones I am having most trouble with - assigning the name of the targetcells workbook
View 9 Replies
View Related
Aug 26, 2009
I'm using an inputbox to let the user select a range of cells. Here's the line
Set MyRange = Application.InputBox("Select cells with numeric data", Type:=8)
When the inputbox comes up, it won't let the user click any cells (or anywhere in the worksheet, for that matter). The cell/range reference has to be typed in manually.
View 9 Replies
View Related
Jul 26, 2006
I keep getting this "Run-time error '1004', Method ' Range' of object '_Global' failed" Here is the code that has the problem:
Option Explicit
Dim i As Long
Dim j As Long
Dim lDup As Long
Dim lRow As Long
Dim NoDupes As Collection
Dim rRng As Range
Dim Rng1 As Range
Dim Rng2 As Range
Dim Rng3 As Range
Dim Swap1 As Variant
Dim Swap2 As Variant
Dim wks As Worksheet
Private Sub UserForm_Initialize()
Call DefaultSet
For lDup = 1 To 3
Call NonDuplicatesList(lDup)
Next lDup
End Sub.....................
It does not even loop once though the original UserForm_Initialize For/Next loop.
View 2 Replies
View Related