Syntax Must Be Incorrect For Range Reference

Feb 13, 2010

The following sub to create and name wsheets results naming the new sheet with the value of "A9" only, but what I want to name the new sheet is "A9" + "B9".
Sub CreateWorksheets()
Dim newSheet As Worksheet, itemSheet As Worksheet
Dim cell As Object
Dim itemrange As String

Set itemSheet = Sheets("BIDFORM")

Application.ScreenUpdating = False
itemrange = "A9:B9:" & itemSheet.Range("A9").End(xlDown).Address
For Each cell In itemSheet.Range(itemrange)
If SheetExists(cell.Value) = False Then
Sheets.Add Before:=Sheets("BACK SHEET"), _
Type:="C:PathFile"
Set newSheet = ActiveShee
newSheet.Name = cell.Value
End If
Next cell
Application.ScreenUpdating = True
End Sub

View 9 Replies


ADVERTISEMENT

VBA Function - Incorrect Syntax

Aug 22, 2007

I'm trying to create a new function in Excel and for some reason the syntax is incorrect and it won't let me use it in the sheet. I do not know what I'm doing wrong so any help would be appreciated. This function will allow me to interpolate the term structure of interest rates between dates (I think) My code is

Function INTSPOT(spots, year)
'Interpolates spot rates to year
Dim i As Integer, spotnum As Integer
spotnum = spots.Rows.Count
If Application.WorksheetFunction.Count(spots) = 1 Then
'Single rate given
INTSPOT = spots
Else 'Term structure given
If year = spots(spotnum, 1) Then
INTSPOT = spots(spotnum, 2)
Else
Do
i = i + 1
Loop Until spots(i, 1) > year
INTSPOT = spots(i - 1, 2) + (spots(i, 2) - spots(i - 1, 2)) * _
(year - spots(i - 1, 1)) / _
(spots(i, 1) - spots(i - 1, 1))
End If
End If

End Function

View 9 Replies View Related

Incorrect Syntax For Setting Value Of Variable

Nov 26, 2013

I'm not sure where my syntax is wrong, and I can't think of what to google to learn more about the possible options I have when creating and declaring the value of variables.

I am simply trying to define the variable aWB as a workbook, whose name is found in cell B6 on the worksheet named "Start" in the workbook named "DW1". This seems to make sense to me, but I am not typing it correctly.

Code:
Dim aWB As Workbook
Set aWB = Workbooks("DW1.xlsm").Worksheets("Start").Cells("B6").Value

View 9 Replies View Related

VB: Incorrect Syntax For Assigning Variables

Jun 3, 2006

I know that I cannot automatically assign UniqueCount the value of that formula. How would I format the line such that I can indeed assign UniqueCount the row value of that line?

View 9 Replies View Related

Syntax Error In VBA Relative Reference Formula

Jan 7, 2014

I was able to get VBA to post this relative reference, which sticks the formula

=DATE(YEAR($D2),MONTH($D2)+6, DAY($D2)+1) into a cell in Col J.

All fine and dandy, works as it should with this formula.

Code:
.Cells(Row, "J").FormulaR1C1 = "=DATE(YEAR(RC4),MONTH(RC4)+6, DAY(RC4)+1)"

However, when I try this with a different formula =IF(ISNUMBER(SEARCH(C2,H2)),"REPEAT","SAFE"), I'm getting a compile error: Expected end of statement with this code:

Code:
.Cells(Row, "I").FormulaR1C1 = "=IF(ISNUMBER(SEARCH(RC3,RC8)),"REPEAT","SAFE")"

The error message highlights the word REPEAT. I suppose it's something with all the quotes throwing off where compiler thinks the end of the formula should be.

View 3 Replies View Related

Correct VBA Syntax To Reference Cells In Functions (Correlation)

Jan 27, 2009

I trying to populate cells with a correlation function using VBA, I have set up dynamic references/arguments for the fuction to take on however I just can't get it to work. Currently instead of populating the formula into the cell, it's just populates it as a string based on what's entered below =correl(Ystart &":"& yend, xstart&'":"'& xend").

FYI - The correl function takes on two ranges,. I've predefined these below.

Sub testing()

lastcell = ActiveSheet.Range("c575").End(xlUp).Row
firstcell = ActiveSheet.Range("c1").End(xlDown).Row

Ystart = ("b" & firstcell)
yend = ("b" & lastcell)

xstart = ("c" & firstcell)
xend = ("c" & lastcell)

Range("c575:c580").Formula = "=correl(Ystart &":"& yend, xstart&'":"'& xend")"

'this works
'Range(xstart, xend).Select

End Sub

View 9 Replies View Related

Counting Amount Incorrect Within A Date Range

Jun 8, 2009

I would like some help from someone on this subject if possible. I am running a stats report in a workbook where each member of staff have their own running totals of how much work they do and how much of that work is incorrect (per week). I have worked out that if I use the following:-

=SUMPRODUCT(('Barry Brooks'!$A$1:$A$2000>=$B$95)*('Barry Brooks'!$A$1:$A$2000<=$C$95))

I get the total amount of work. To explain the above, it returns the amount of times a date appears between two dates i.e B95 is week commencing date and C95 is weekending; therefore giving the total amount of work in that period.

What I am struggling with is that I need a formula to look at the above date range and then look at another column that has either a ‘Y’ or ‘N’ (for yes or no) and for the formula to count how many N’s there are (thus how many in that given range there were)

It appears to me quite a small ask for Excel but I can’t seem to get it to work.

View 6 Replies View Related

If Else Syntax: Change Some Outputs Of The Macro Without Changing The Syntax

Jul 19, 2006

I´m writting a macro. It works find until a certain point. When I want to change some outputs of the macro without changing the syntax, it display an error mesage while runing the macro. It says Else without If. Which is quite disturbing because the Else was not creating any problem before. Here is my macro before I changed the conditions (this one work nicely)

Sub Copy_Sheet_Beta()
Set wba = ActiveWorkbook
On Error Resume Next
If IsWorkbookOpened("Projekt.xls", "C:Documents and SettingsfrederikSkrivebordRedd Barna") Then
Workbooks("Projekt.xls").Activate 'In case open, just activate "Projekt"
Else
Workbooks.Open Filename:="C:Documents and SettingsfrederikSkrivebordRedd Barnaprojekt.xls"
End If
Set wb = Workbooks("Projekt.xls")
wb.Activate
If Not SheetExists(wba.ActiveSheet. Range("C1").Value) Then
MsgBox "overall doesn't exist!"
Else........................................

View 2 Replies View Related

Number Range Syntax In VBA?

May 4, 2014

[Code] ......

I seem to be having trouble with the syntax the number range after (iPopFreqMax).

View 1 Replies View Related

Tweak Of Syntax On Named Range

Nov 17, 2008

just need a hand tweaking the syntax on a names range.

Range 1

=INDEX(Sheet2!$C:$C,5):INDEX(Sheet2!$C:$C,ROW(LRow)-1)
LRow: Is a named active row for the last row. [say row 10]

This named range only selects ONE Column

How can I get it to select TWO columns [ie C & D] as in the example below does. It does it by the last number 2, goes two columns wide?

Range 2

=OFFSET(Sheet2!$C$5,0,0,COUNTA(Sheet2!$C:$C),2)
I can't figure out how to express that in the Range 1?

View 9 Replies View Related

Numerical Syntax For Range Object

Feb 27, 2008

is it possible to write Range("A1:H6") without the string inside the range brackets? i'm trying to do is pass numerical column values into the Range function, and i'd rather not make a mess using the CHR function (CHR(65) = "A", for example).

View 2 Replies View Related

Advanced Filter Syntax For Copy To Range

Oct 16, 2013

I thought I had this cracked last month when I ran a set of reports using some code dependent on using advanced filters to first create a unique list to loop through and then to create a list of all entries in a list for each unique entry. The idea being that I extracted all the data for each unique entry in the list and saved that to a new workbook, named after the unique entry.

However, this month I'm totally flummoxed again. I can't seem to get even the first part, creating a unique list, to run.

I have a sheet with several thousand rows of data with maybe 25 columns. I have the following code to try to extract the unique entries in the 2nd column, column B and store them in the same worksheet in column AD, to use when looping through the list.

VB:
With ActiveSheet
.Range("AD1").EntireColumn.Delete
.Range("A1").CurrentRegion.Columns(2).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheet1.Range( _

[Code].....

View 9 Replies View Related

Syntax Range - Getting Runtime Error 1004

Feb 15, 2013

I know you can use the syntax range(cells(x,y),cells(z,w)) but for some reason unknown to be the following isn't working:

Set CurrSuppRange = TT.Range(Cells(1, CurrSuppCol), Cells(LastRow, CurrSuppCol))
where
CurrSuppCol = cboxCurrSupp.ListIndex
OurSuppCol = cboxOurSupp.ListIndex
LastRow = Workbooks(lbWkBkName.Caption).Worksheets(cboxWorksheet.Value).Cells(Rows.Count, "A").End(xlUp).Row
(each return integer values)
Set TT = Workbooks(lbWkBkName.Caption).Worksheets(cboxWorksheet.Value)

(tested and works fine)

View 2 Replies View Related

Indirect Formula Syntax For Referring To A Range On Two Worksheets

Jul 5, 2012

B1=Name of WorkSheet
B2=Name of 2nd Worksheet

I am trying to write a sum formula using Indirect so that the end-user can enter the names of the sheets in B1 & B2 (the values are always in cell F5 on each sheet). I thought this would work but it is throwing a REF# error.

=SUM(INDIRECT("'"&B1&":"&B2&"'!F5"))

with some added spaces for clarity:

=SUM(INDIRECT(" ' " & B1 & " : " & B2 & " ' ! F5"))

View 9 Replies View Related

Paste Values To Next Empty Row In Range On Another Sheet Syntax

Jun 27, 2014

I have the following code to transfer data to another sheet, but there are 2 issues with it:

1. I want to just paste the values, but every code I have tried has had object or syntax errors that can't seem to be fixed

2. If I run the macro a second time, it overwrites what was pasted the last time the macro ran. My code looks like it should look for the next empty row in the range, but it doesn't seem to do that.

What is the correct syntax to do the above. Here is the code:

Sub Update()

Dim c As Object
Dim rngA As Range
Dim cc As Object
Dim rngAA As Object

'Check every cell in the range for matching criteria.
For Each c In Sheets("OpenGen").Range("F9:F208")

[Code] ..........

View 2 Replies View Related

Loop Syntax: Method Range Global Error

Aug 31, 2007

This line fails, is Method Range Global error.... What is wrong w/ this, and how should it read?

If Range("D", i).Value = "Need Parent" Then
2nd Question- The following line is my normal method in doing a simple For Next Loop. What is the difference between using this one, looping through the cells and the first one referring to a Range for the loop?

If Cells(i, "D").Value = "Need Parent" Then

View 9 Replies View Related

Basic Range Copy, Match Sheetnames: Logic, Style, And Syntax

Feb 11, 2009

I am wondering if using an "if" statement or a case statement would be good ways to check two worksheets in two different workbooks to see if their names match? I could use some help correcting my syntax too:


For 1 to ws.count
If Worksheet("one").Name = Worksheet("two").Name
Worksheet("one").Range("A1:G84").Copy
Worksheet("two").Range("A1:G84").Paste
Endif
Next ws.Count

View 9 Replies View Related

Correct Syntax For Function To Find Average Based On Background Color Of Cells In Range

May 20, 2014

I'm working on a workbook that will track staffing patterns.

The workbook has three worksheets: Sheet1 "RCS", Sheet2 "HCT' and Sheet3 "Hidden". I've attached the workbook to this thread. The password for the form is "j".

On Sheet3 "Hidden" I have two tables that are set up to collect the SUM of columns on Sheets1 "RCS" and Sheet2 "HCT". I'm finding the SUM of each range by way of the background color. I've set up the following formulas and when the "data collection tables" are in the same worksheets as the original information, the formula's work perfectly:

The following functions are pulling data from Sheet1 "RCS" and placing them into a table in Sheet2 "Hidden"

[Code] ........

The following functions are pulling data from Sheet1 "RCS" and placing them into a table in Sheet2 "Hidden"

[Code] .......

I have two more functions that aren't working due to the fact that the source values are percentages and NOT plain numbers. The above functions work great for SUM but not for percentages. EXAMPLE--Let's say, 3 sub percentages it gives me the SUM of the 3 percentages (i.e. 85% + 100% + 100% = 285% instead of giving me 95%.

[Code] ........

How might I use the following functions to find the average of the source fields instead of the SUM?

View 7 Replies View Related

How To Reference Cells Value To Define Range Reference

Jul 14, 2014

Is it possible to reference a cells value to define a range reference?

[Code] ......

I am trying to define the row value in the range reference with a value in a secondary cell?

View 3 Replies View Related

How To Create Range Within Range Using Row / Column Reference

Jul 21, 2013

I have a range that I named. Let's say that range is called "RangeX". Let's say RangeX is defined by B2:E10

I have a series of formulas that give me the row and column numbers of the starting and ending cell of a subset range I want to create within RangeX. Let's say the starting cell is defined by (1,1) and the ending cell is defined by (3,4) within RangeX. Translated, the starting cell would be B2 and the ending cell would be E4.

How do I create a subset range using the starting cell (1,1) and (3,4) in VBA? I would like to use the row/column reference as RangeX itself could move around.

View 1 Replies View Related

Reference Cell Looks At One Range Then See If Any Exist In Another Range

Oct 21, 2009

I have a workbook with two sheets. The first sheet is the data sheet.

Data Worksheet
A B C D colA colA,B colA,B,C colA,B,C,D
104 20 21 CR10600S 104 10420 1042021 1042021DUS
104 20 21 CR10600SX 104 10420 1042021 1042021DUS
104 20 21 CR10603S 104 10420 1042021 1042021DUS
104 20 21 CR10603SX 104 10420 1042021 1042021DUS
104 20 22 CR49605S 104 10420 1042022 1042022HKZ
104 20 22 CR49605SX 104 10420 1042022 1042022HKZ
104 20 23 CR39601P 104 10420 1042023 1042023SPR
The next sheet is where the magic happens. Separate this worksheet into two sections. The reference section (column A and B) and the entry section (column E-G). Column D is a formula that will concatenate column E-G together. In the entry section any number of combinations can be entered. In the reference section I need to take the style number and reference it back to the data sheet. Then take the possible combinations from that style (column E and greater) and see if any of those combinations exist on the other sheet in column D. If so then say added....otherwise say needed.


"....In Pricing Sheet" is where I am looking to put needed or added or something like it.
A B C D E F G
STYLE …IN PRICING SHEET Concat DEPT MCL SCL STYLE
CR10600S Added 1042021 104 20 21
CR10600SX Added 1042022 104 20 22
CR10603S Added
CR10603SX Added
CR49605S Added
CR49605SX Added
CR39601P Needed
Any ideas on how to do this in formulas and without code? I have tried and looked into index, match, dget and lookup. I just don't think I am finding the right combination of formulas.

View 9 Replies View Related

Wildcard Incorrect

Dec 7, 2007

I have tried everything I can think of to get this to work.

I am searching column B for anything containing "Tease", then if found, look to see if column J contains a "W".

Excel doesn't report an error, but this doesn't work:

=SUMPRODUCT((B3:B40="*Tease*")*(J3:J40="W"))

View 10 Replies View Related

IF, AND, OR - Returns Incorrect Value

Apr 29, 2009

I am having problems with the following formular in that it does not return what I am expecting.

I have 2 columns of data that hold Y/N values and I would like either "Yes" or "No" to be displayed in Col C for the 4 possible combinations that the interaction of Y and N in columns A&B give.

The data is
Col A:A = Y or N
Col B:B =Y or N

The four possible combinations and outcomes are:
Col A = Y & Col B = Y outcome in Col C = "Yes"
Col A = N & Col B = Y outcome in Col C = "Yes"

Col A = N & Col B = N outcome in Col C = "No"
Col A = Y & Col B = N outcome in Col C = "No"

The formular I have tried is:
=IF(OR(AND(A1="Y",B1="Y"),A1="N",B1="Y"),"Yes","No")

However while three of the outcomes for the combinations are correct (N/Y, Y/N, Y/Y), the output for the N/N combination is incorrect and returns "Yes" instead of "No".

Just wondering if anyone has any ideas as to what is wrong with this?

View 9 Replies View Related

VLOOKUP Returning Incorrect Value

Nov 28, 2012

I've created a spreadsheet to 'translate' number/letter combinations (sub-levels in the UK education system) into a numerical value. I looked up how to do this on google and, through a bit of trial and error, worked out that the lookuptable has to be in alphabetical order, etc.

My problem is when I enter in any of the 'P' values (see attached), it returns 0.5.

View 4 Replies View Related

Deleting Incorrect Cell Name?

Jun 24, 2014

I have a lot of calculations going on so I thought I would name some of the cells where factors come from to make it easier to follow.

I made a typo and named a cell wrong, is there a way to delete it? Right now I have a correct and incorrect name attached to the cell.

View 3 Replies View Related

Save Path Is Incorrect

May 27, 2009

I have the following code, taken from an example off the web. But I would like to change the save path to just C/: rather than copy the save path of the original file...I would also like to not close the active workbook that I am working in....how can i achieve this?

Sub TwoSheetsAndYourOut()
Dim NewName As String
Dim nm As Name
Dim ws As Worksheet

If MsgBox("Copy specific sheets to a new workbook" & vbCr & _
"New sheets will be pasted as values, named ranges removed" _
, vbYesNo, "NewCopy") = vbNo Then Exit Sub

With Application
.ScreenUpdating = False

On Error GoTo ErrCatcher
Sheets(Array("Copy Me", "Copy Me2")).Copy
On Error GoTo 0
For Each ws In ActiveWorkbook.Worksheets
ws.Cells.Copy
ws.[A1].PasteSpecial Paste:=xlValues....................

View 2 Replies View Related

Incorrect Scoping Of Variable?

Mar 1, 2012

I have two pieces of code in module 1 and module 2 respectively:

This code is meant to find the first row number that has a string value of "" in column A:

HTML Code:
Sub Macro1()
Dim cell As Range
Dim r As Double
Dim p As String
For Each cell In Worksheets("stock in").Range("stockcode")
p = cell.Value
r = cell.Row
If p = "" Then Exit For Else
Next cell
End Sub

BTW column A will contain formulas that evaluate to "" so I assume cell.value will = "" even if it contains a formula?

In the second module a sort is executed on the range based on the number of rows:

HTML Code:
Sub Macro2()
'
' Macro2 Macro
'
Call Macro1

ActiveWorkbook.Worksheets("Stock in").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Stock in").Sort.SortFields.Add Key:=Range("A4:A" & r) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

[Code] .......

My code is falling down because I think my variables arent scoped right or my code is in the wrong place. Also macro1 will eventually be executed from a button on a different sheet (I dont know if this will matter).

The whole point of this code is to get around the fact that if you perform A - Z sorts on cells that contain formulas those that evaluate to "" will be at the top leaving lots of blank rows before actual visible data.

View 9 Replies View Related

Incorrect Result Of IF Statement

Jun 27, 2012

I have a line of code that compares cell values with a variable.

Code:
dim rmycell as range
If rmycell.value = MyTarget then

This works fine when rmycell.value is empty or has a value. However, sometimes rmycell has a #VALUE! Error. When debugging the code I can see this error showing rymcell with a value of "Error 2015". The MyTarget variable is "abcdefg", so the If statement should resolve as

Code:
If rmycell.value = MyTarget then
becomes
Code:
If Error 2015 = "Abcdefg" then

Which should be a negative result. Except it isn't. The code that is conditional on a positive result runs whenever there is a #VALUE error, just as if the 2 values were equal.

View 3 Replies View Related

Identifying Incorrect Data.

Feb 10, 2009

In column H I have a list of numbers seperated by a space, the number of lines can change. In column L I have a list of numbers which can change either expand or retract.

I would like to check each cell in column H and if any numbers are not listed in column L then it/they should be shown in column G.

Example1 H2 shows 6 11, therefore cell G2 should show 11.

Example 2 H6 shows 5 6 9 11 therefore G6 should show 9 11

Sheet1  HIJKL1Container   ID26 11   135 8 11   245 7 11   355 7   565 6 9 11   675 6 9     Excel tables to the web >> Excel Jeanie HTML 4

View 9 Replies View Related

Incorrect 'Last Cell' In Worksheet

Aug 26, 2006

CTRL/END key combination should goto and select the last cell in a Worksheet. So for a Worksheet using Rows 1-4135 and Columns A-Z it should indicate Z4135 as the last cell
My current worksheet uses these Rows and Columns, but CTRL/END indicates last cell as being AB4506. (Inflated by 371 Rows and 2 Columns)

Deleting the unwanted Rows or Columns, or "Clearing contents" of them does not affect the result given by CTRL/END which still shows AB4506.

How can I adjust/correct the last cell indication?

Usual work-around is to select the wanted portion of the worksheet and copy it to a new blank worksheet, but is there an easier way?

View 5 Replies View Related







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