Setting A Range Object Variable's Address

Apr 1, 2009

Here is my code


Dim LastCell As Range
Set LastCell = Cells(EndRow, LastCol).Address

I get a "Object Required" when this I try to set the address. I know this is easy.

View 9 Replies


ADVERTISEMENT

Object Required Error Setting Range Variable

Aug 22, 2007

code is getting an error on the bold line below. My error message is run time error 424 - object required.....

View 7 Replies View Related

Setting Variable As Data Range?

Dec 12, 2011


I am attempting to set a variable as a range of data that sits on a non-activated worksheet. However, I am getting a runtime error of 13 (data mismatch).

Is there something in my code that may be incorrect? Here is my code:

Dim rRange As Range
Dim sRange As String
Dim tblName As String

[Code]......

View 4 Replies View Related

Setting A Range Using String Variable

Jan 8, 2014

I'm having trouble setting the Range "UtilizationRange" using a variable, "CurrentRange" to store that range. I get the error "Run-Time error 1004: Method 'Range' of object'_Global' failed".The rest of my code works when I set the utilization range using the actual range for my purposes, but the problem is the range will change each month and I don't want to change it manually each time. There's a cell in the excel sheet this refers to (AG3) that holds the range value, which in this case is [N7:N75], and I would just like to return that value to the variable "CurrentRange" and set UtilizationRange equal to that.

The value is returned to CurrentRange, but it's the last line that's giving me the problem.

Sub RangeTest()Dim UtilizationRange As Range, Cell As RangeDim CurrentRange As String
CurrentRange = Range("AG3").Value MsgBox (CurrentRange)
'This returns the value [N7:N75], which is what I want
Set UtilizationRange = Range("CurrentRange")End Sub

View 1 Replies View Related

Error Setting Range Variable

Aug 8, 2006

i have compiled a multipage using some borrowed code and some code i have written myself. most of it works, but i have a problem populating listbox2.the error is in Private subCmbFindAllJobNo_Click(). i have put h1 tags around the line of code which shows the error when i debug. this code works ok as a stand alone, so i suspect i have done something wrong in the userform initialise.

Option Explicit
Dim rng As Range
Const FirstRow As Long = 2
Dim r As Long
Dim ans As Variant
Dim MyArray(100, 4)

Public MyData As Range, c, d As Range

Private Sub cmbAmend_Click()

Application. ScreenUpdating = False
Set c = Worksheets("ENTRY SHEET").Range("b4").End(xlUp).Offset(3, 0)
c.Value = Me.DTPicker1.Value
c.Offset(1, 0).Value = Me.TextBox1.Value
c.Offset(2, 0).Value = Me.TextBox2.Value ..........

View 9 Replies View Related

Setting Values In A Variable Range Occurence Query

Jul 18, 2006

I am trying to count the occurences of combinations within a range defined by contiguous cell values in one column. My problem lies with setting the value of variables that are queried within the defined range. My macro should;

1)Set ComboValue1 & ComboValue2 values to A1 & B1 cells values respectively
2)define range to be searched by how many contiguous values there are in column D
3)search column E for 2 figure combination (defined by A1 & B1). If present increment counter by 1 and add to column C (to be visible in worksheet). If no match carry on
4)define new range by next set of contiguous values in column C
5) step 3
6)when all possible contiguous ranges defined and searched from column c, perform again on next combination down columns A & B with refreshed occurence counter
7)finish when all combinations are searched for

Sub CountComboOccurence()
Dim ListCounter As String
Dim ProgCounter As String
Dim Counter As Integer
Dim ComboValue1 As String
Dim ComboValue2 As String
Dim Rng As Range
Application. ScreenUpdating = False
ListCounter = 0
ProgCounter = 0
Counter = 0
ComboValue1 = 0.......................

View 2 Replies View Related

Subcript Out Of Range Error Setting Worksheet Variable

Sep 13, 2006

Subcript Out Of Range Error Coming Now For The Code Which Works For Me Before


Sub WHideRows()

Dim rRange As Range, rCell As Range
Dim strVal As String

Set rRange = Worksheets("WIED PROBLEM WELLS").Range("A11:A110")

For Each rCell In rRange
strVal = rCell(1, 3) & rCell(1, 4) & rCell(1, 5) & rCell(1, 6) & rCell(1, 7) & rCell(1, 9)
rCell.EntireRow.Hidden = strVal = vbNullString
Next rCell

End Sub

i am using the code above to hide the rows which doesn't have any values in all the following Cells 3,4,5,6,7 & 9 or Unhide the rows if there is value in any 1 of the following cells 3,4,5,6,7 & 9 from row number A11 to A110.

The same code works for me before. But now the code is not working. It says below the error message

Run-time error '9':..................

View 9 Replies View Related

Variable Numbers Used In Range Address

Jul 14, 2006

I need to select a variable number of cells on a line. I know Range("A2:c2") will do exactly what I need EXCEPT i need to use variables to do it. Is this possible, and if so how.

View 5 Replies View Related

Selected Range Address To Variable

Feb 20, 2008

I have created a work diary in Excel which is built up in half hour blocks. I am able to create my appointments (usually one or two hour blocks) by selecting a group of cells and running a macro which merges the cells, colours them and puts a border round them.

I now want to be able to delete individual appointments by selecting the appropriate appointment and running a macro to copy and paste from the same range of cells in another worksheet (which is effectively my blank master diary page).
I have tried work out what code I need to put the range of the current selection into a variable in VBA but I'm not having any luck.

View 2 Replies View Related

Creating Range Object Using Variable Indices

Mar 28, 2008

how do we do something like Range("A1:B2") using an index for the cells. For example Range(R[0]C[0]:R[i]C[j]) which doesn't work. I know about Cells(i,j), but that only returns a range object of a single cell.

View 9 Replies View Related

2007 Macro: Run-time Error 91:Object Variable Or With Block Variable Not Set

Feb 20, 2009

I'm fairly new to macro's and VBA, by searching on the internet i've copied and pasted some code together into a macro.
But it ends in a Run-time error 91...

The macro opens a target .xls file in a selected folder, performs copy - paste actions from masterfile to targetfile.
Than it filters data in the targetfile sheet1 and copy's the results to the various other sheets; saves and closes the targetfile.
The next target file in the folder is opened and the actions are repeated in this second target file.
For the first target file this works smoothly; but for the second one (of a total of around 100) it does not copy the filter results to the other sheets in this workbook.
The error message i get is: "Run-time error 91:Object variable or with block variable not set."
When i hit debug it highlights the line "ActiveSheet.Next.Select" which, at least in the first file, seems ok.

View 9 Replies View Related

Excel 2007 :: Object Variable Or With Block Variable Not Set Error

Feb 28, 2013

I Wrote a code which as intended to open each excel file in a folder and copy the data containing in it into a new sheet.

But While running the code the first excel file gets open, and an error message "Run Time Error 91-Object Variable Or With block Variable not set Error"

How to set the file which got opened from the folder to wbk variable.

Code:
Sub dataintoonesheet()

Dim i As Integer
Dim jk As Integer
Dim j As Integer

Dim rowstart As Integer
rowstart = 3

[Code] .......

View 9 Replies View Related

Macro Error Message (object Variable Or With Block Variable Not Set)

Jul 7, 2009

When i try to run the code below i get the error message - object variable or with block variable not set-

Sub REFRESHXX()

'LIST
Cells(Sheets("POINTS").Range("DD801").Value, Sheets("POINTS").Range("DD800").Value).Select
Selection.AutoFilter Field:=1, Criteria1:="1"
'SET RANGE
Dim sFormula1 As String
Dim sFormula2 As String
Dim sCell1 As String
Dim sCell2 As String
Dim sSheet1 As String
Dim sSheet2 As String
Dim r As Range
Dim MyRange As Range 'for testing

With Sheets("Points")
sFormula1 = .Range("CY1").Formula
sFormula2 = .Range("CY2").Formula
End With

'FORMULA IN R1C1 STYLE
strFormula = "=IF(ISNA(VLOOKUP(RC[-1],MASTER!R4C3:R17908C7,3,FALSE)),0,VLOOKUP(RC[-1],MASTER!R4C3:R17908C7,3,FALSE))"
'ENTER FORMULA IN ALL CELL RANGES
r.FormulaR1C1 = strFormula
'REDUCE TO VALUES
Dim ar As Range 'an area is a range
For Each ar In r.Areas 'areas are discrete, contiguous ranges of cells
ar.Value = ar.Value
Next ar

'UNLIST
Cells(Sheets("POINTS").Range("DD801").Value, Sheets("POINTS").Range("DD800").Value).Select
Selection.AutoFilter Field:=1

End Sub

View 9 Replies View Related

Find Method Code: Object Variable Or With Block Variable Not Set

Sep 8, 2006

I need my program to:
- find the cell containing the string "Datum/Tid"
- record the column and the row of the found cell in two variables lCol and lRow

Here is my

Sub test()

Dim rFoundCell As Range
Dim lRow As Long
Dim lCol As Long

'Find method of VBA
Set rFoundCell = Range("A1")
Set rFoundCell = Worksheets("Sheet1").Range("A1:Z50").Find(What:="Datum/Tid", After:=rFoundCell, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

'for anyof the two lines down I get the message "object variable OR block variable not set"

lRow = rFoundCell.Row
lCol = rFoundCell.Column

End Sub

View 5 Replies View Related

Find Dates Macro: Object Variable With Block Variable Not Set

Nov 21, 2006

I found this nice little bit of code for a date range search in column A but it will not work. Apparently i have not set a variable or something.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim startDate As String
Dim stopDate As String
Dim startRow As Integer
Dim stopRow As Integer
startDate = InputBox("Enter the Start Date: (dd/mm/yyyy)")
If startDate = "" Then End
stopDate = InputBox("Enter the Stop Date: (dd/mm/yyyy)")
If stopDate = "" Then End
startDate = Format(startDate, "dd/mm/yyyy")
stopDate = Format(stopDate, "dd/mm/yyyy")
startRow = Worksheets("sheet1").Columns("A").Find(startDate, _
LookIn:=xlValues, lookat:=xlWhole).Row
stopRow = Worksheets("sheet1").Columns("A").Find(stopDate, _
LookIn:=xlValues, lookat:=xlWhole).Row
Worksheets("Sheet1").Range("A" & startRow & ":A" & stopRow).Select

End Sub

View 9 Replies View Related

Runtime Error 91 Object Variable Or With Block Variable Not Set

Mar 24, 2014

I am getting error in Set MyRange

[Code] .....

View 3 Replies View Related

Object Variable Or With Block Variable Not Set Error With Macro

Mar 12, 2009

I attempted to modify "macro_1a1ay" to look into the "comments" sheet (column a) for a specific text string. If that text string is found, I have it delete the entire row, then re-sort the page and return to the calling page. It works well as long as it finds something. When it does not find the string (i.e. like now when the page is blank) it gives me the run-time error mentioned above.

View 7 Replies View Related

Run Time Error 91 Object Variable Or With Block Variable Not Set

Oct 7, 2009

I am having a lot of trouble finding out why I am getting error. I believe the error is because it can't find the number. In cells C115:C314 i have the numbers 1 to 200 in order. when someone types in 1 to 9 in the text box it works, but on 10 and over i get the error ???? here is the code I have

shCalculator.Range("C115:C314").Select
Selection.Find(what:=CInt(txtPackageID), After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Select
x = ActiveCell.Row
shCalculator.Range("ProposedMeter").Value = Cells(x, 7).Value
shCalculator.Range("Package").Value = Cells(x, 12).Value
shCalculator.Range("ProposedMeterAmount").Value = Cells(x, 30).Value
shCalculator.Range("Term").Value = Cells(x, 62).Value
shCalculator.Range("Discount").Value = Cells(x, 67).Value
shCalculator.Range("Equipment").Value = Cells(x, 72).Value

View 3 Replies View Related

Two Macros - Object Variable Or With Block Variable Not Set Error

Jul 11, 2014

I have two macros that run fine separately. I want to join them, but when I do I get an Object variable or With block variable not set error.

Here's the code

Code:

Sub border_highlight_insert()
' Change heavy border to new column, change tint - keyed to year A6
With ActiveSheet
Dim i As Integer

[Code]....

View 2 Replies View Related

Runtime Error 91, Object Variable Or With Block Variable Not Set

Feb 6, 2009

This works fine in Excel 07 but when ran in 03 it doesn't work and I get that error message.

Sub mcrRefresh2()
Sheets("WeeklyData").Range("A1").ListObject.QueryTable.Refresh BackgroundQuery:=False
Sheets("WeeklyData").Range("aa1").ListObject.QueryTable.Refresh BackgroundQuery:=False
Worksheets("WeeklyPivot").PivotTables("PivotTable1").PivotCache.Refresh

End Sub

View 9 Replies View Related

Debugging Error: Object Variable Blocked Variable Not Set

Nov 9, 2009

I am getting an error at this line:

Set rng5 = Range(.Cells(celle2.Row, celle4.Column), .Cells(celle2.Row, celle4.Column))

Sub UpdateNumbers()
Dim rng1 As Range
Dim rng2 As Range
Dim rng3 As Range
Dim rng4 As Range
Dim celle1 As Range
Dim celle2 As Range
Dim celle3 As Range
Dim celle4 As Range
Dim celle5 As Range
Dim flag1 As Long
Dim flag2 As Long................

View 9 Replies View Related

Find Method: Object Variable Or With Block Variable Not Set

Aug 28, 2006

I have a spreadsheet form with all kind of values and what I want to do is to find a data in a worksheet named "Config" based on the spreadsheet activecell value. With the find row adress I return data of another column but same row (in the worksheet) in two diferent label captions. If the spreadsheet activecell value it was found in the worksheet everything is ok but if the value is not found I'm getting the message "Object variable or with block variable not set"....

View 7 Replies View Related

Run Time Error 91, Object Variable Or With Block Variable Not Set

Jan 14, 2007

Function Find_Range(Find_Item As Variant, _
Search_Range As Range, _
Optional LookIn As Variant, _
Optional LookAt As Variant, _
Optional MatchCase As Boolean) As Range
Dim c As Range
If IsMissing(LookIn) Then LookIn = xlValues 'xlFormulas
If IsMissing(LookAt) Then LookAt = xlPart 'xlWhole
If IsMissing(MatchCase) Then MatchCase = False
With Search_Range
Set c = .Find( _
What:=Find_Item, _
LookIn:=LookIn, _
LookAt:=LookAt, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=MatchCase, _ ........................

Using the message box I see that sheet 1 opens but then I receive an error message Run Time Error 91, Object Variable or With Block Variable not set. I tried declaring and using set on "project" but got nowhere. I also need to have a message indicating project not found. Once this part is solved I will loop all of my other workbooks

View 5 Replies View Related

Error - Object Variable Or With Block Variable Not Set

Jun 20, 2007

I've got a simple Macro which manipulates data in various worksheets. Problem is that I get the error: "object variable or with block variable not set" in the area of the code that I have put in bold below:

All I'm trying to do in this part is find the first occurrence of the #n/a value ....

View 12 Replies View Related

Error: Object Variable Or With Block Variable Not Set

Mar 3, 2009

I've set up a userform (frmCoC) to read and write info to the "contractor database". Within that userform is a listview control that reads off a second, "induction database".

When the user selects and clicks on one of the displayed entry in listview, another form (frmInd) opens to edit data on the induction database.

There's a command button along side the original form (frmCoC) to create a new entry in the induction database. The click event for the button is as follows:

View 8 Replies View Related

Error 91 / Object Variable Or Blocked Variable Not Set

Nov 17, 2011

I only get the error 91 "object variable or blocked vairable not set" when the below code is used or loaded in Internet Explorer IE 9 browser but works fine in Excel.

Public Sub CommandButton9_Click()
Dim myDir As String, fn As String, wb As Workbook, rng As String
myDir = "C:DatabaseCust_Name"
fn = TextBox2.Text
On Error Resume Next
Set wb = Workbooks(fn)
If wb Is Nothing Then

[code].....

View 9 Replies View Related

Object Variable Or With Block Variable Not Set Message

Aug 29, 2013

I'm trying to run some code but I keep getting the Object Variable or With Block Variable Not Set message. I'm not using any object in the line that is causing the error.

I'm getting an error on the last line of given code

Code:
Private Sub addDescriptions(BucketTotal as Double, Descriptions as String)
Dim DCELL as Range
'''Loop Through Controls'''
For i = 1 to 20
if Controls("TR" & i).Value = "" Then
Exit For
Else
Set DCELL = Columns("F").Find(Controls("DivRate" & i), Lookin:=xlValues, Lookat:=xlWhole).Offset(0,3)

View 7 Replies View Related

Error 91 Object Variable Or With Block Variable Not Set

Oct 23, 2009

At a high-level: My code fails in the sub-routine that is called (SecondSub). The first line of code on the SecondSub is where I get the Error 91 Object Variable or with block variable not set.

1st Routine:
________________________________________________________
Sub FirstSub()
Dim ie As Object, iebody As String, strURL As String, strUsername As String, strPassword As String
Dim lRow As Long
Dim abc As String
Dim striEst As String
Dim ele As Object
Dim LinkHref As String
Dim a As String
Dim b As String
Dim c As String
a = DateAdd("d", -1, Now)
b = DateAdd("d", -2, Now)
c = DateAdd("d", -3, Now)

Set ie = CreateObject("InternetExplorer.Application")
strURL = "website"
strUsername = "xxxxxxxxxxx"
strPassword = "xxxxxxxxxxx"
While ie.busy
DoEvents
Wend......................

View 9 Replies View Related

CreateObject: Object Variable Or With Block Variable Not Set

Nov 29, 2006

I have my below code which will create a looping "ftp" and "get" effect.
However i am having some problems right now. There's always an error that states "Object variable or With block variable not set".

Sub File_Transfer_testing()

Dim N As Integer
Dim Lotid As Variant
Dim Tester_array(1 To 15) As String

Tester_array(1) = "10.10.10.10"
Tester_array(2) = "20.20.20.20"

Lotid = InputBox("Input a LOT ID")

N = 1

Set fs = CreateObject("Scripting.FileSystemObject")
Set A = fs.CreateTextFile("C:script.txt", True)
For N = 1 To 2
A.writeline "open " & Tester_array(N)
A.writeline "xxx" 'username
A.writeline "xxxxxx" 'password
A.writeline "cd /zzz/reports"
A.writeline "prompt"
A.writeline "ascii"
A.writeline "mget " & Lotid & "*sorts" 'file to be uploaded
A.writeline "quit"
A.Close

Set fs = CreateObject("Scripting.FileSystemObject")
Set A = fs.CreateTextFile("C: upload.bat", True)
A.writeline "ftp -s:C:script.txt" 'the ftp site
A.Close

dRetVal = Shell("C:upload.bat", 0) 'upload the file
''''''''''end upload.bat file
Next
MsgBox ("Done")
End Sub

View 3 Replies View Related

Activate Cell Address Behind Object

Feb 15, 2007

I have a piece of clip art in a cell (that moves around in the right cell when i filter/sort the data). i need to know how to select/activate the cell that a piece of clip art housed in. is there a way to say at the beginning of the macro to select the cell behind the picture?

Macro works by offsetting a few cells to the left and pulling the name of the item in that row and then going to another worksheet that is named the same thing as what is in the cell i offset to. If i click on the cell behind the picture first then it works but if i have a diff cell activated when i click the picture it of course doesnt work - so all i need is a way to activate the cell behind the picture.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved