Find Variable's First Row And Last Row
Feb 22, 2014Column A:
A
A
A
B
B
C
C
C
D
D
D
D
I would like to find the row that the first and last C is at.
first and last row should be 6 and 8 respectively.
Column A:
A
A
A
B
B
C
C
C
D
D
D
D
I would like to find the row that the first and last C is at.
first and last row should be 6 and 8 respectively.
After doing a search, I need to ask an Excel 2003 question. I'm creating a tool to open three sparate workbooks. One is the driver and I need to use it to pull data from the second and then to place that data along with additional data into the third.
My driver data may consist of a single value or multiple values separated by semi-colons in a cell. A single value works fine. The first value in a multi-value condition works fine. the second find, however, gives me an object error. I'm using the " split" verb to separate the values. Here's my code. Have you any idea why the second find is throwing up this error when the first find works correctly?
varData = Split(strRef, ";", -1)
For J = 0 To UBound(varData)
varSrchVlu = Trim(varData(J))
' do the ARIS Exrtact matching
Workbooks(strManualFile).Activate
Workbooks(strARISExtract).Activate ' Activate ARIS Extract
Sheets("Processes").Cells(2, 1).Activate
Workbooks(strARISExtract).Sheets("Processes").Range("A2").Select
Workbooks(strARISExtract).Sheets("Processes").Columns("A:A").Select
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
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
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 RelatedI'm trying to write code, that uses a variable when using the find function. When I put the variable in the "WHAT" it's not reading the value.
Here's my code:
For f = 1 To g
H = ActiveCell.Value
Sheets("IPO TEMPLATE").Activate
Cells.Select
Set FindQueryUPC = Selection.Find(What:="H", After:=ActiveCell, LookIn:=xlValues, _
[Code] ..........
I'm trying to find cells in a range that have a date >= today.... this wont work:
Set Cell = .Find(What:=Cell.Value >= Date, After:=.Cells(1, 1), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
Can it be adapted at all?
I am trying to find the max value within a range (14 cells) contained in one column ("C" in this case). This range will change corresponding to the current cell. Ex. as the current cell moves down (or increases in number) the range of cells to find the Max in moves down (or increases in number) as well. The Max value will then be used as a variable in a equation but for now just getting it into a cell is fine. This seems like it would be easy but it is driving me absolutely batty!
I currently have the non-working code located in a For loop that contains other calculations as well. I've taken those calculations out since they work fine but cloud the bad part. So far I have tried:
The initial code was from this forum. I modified it so it wont work
The code finds the first instance but none after, why?
I'm creating a macro with several brands in a variant variable.
The only thing that isn't working, is the find function. I want to find "Brand" & variable. So when my variable is "medicijn1", then I want to find "Brand medicijn1". However, when I try, it gives me the following error:
"run-time error '91': Object variable or with block variable not set".
The macro basically looks like this
Sub Medicijnen()
Dim Medicijn As Variant
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each Medicijn In Array("medicijn1", "medicijn2", "medicijn3", "medicijn4"")
[Code] ......
I have a large amount of data Range A1:DA6000 on Sheet2 in the following format:
120200 1885 | 42.43 | 130112 1992 | 49.65
120200 1886 | 45.95 | 130112 1993 | 48.08
120200 1887 | 47.65 | 130112 1994 | 49.77
120200 1888 | 45.97 |
120200 1889 | 48.34 | 130133 1887 | x
120200 1890 | 49.42 | 130133 1888 | 41.6
120200 1891 | 48.85 | 130133 1889 | 45.45[/list]
Cell A1 Sheet1 will be variable and I need to find the same value on Sheet2 in all that data and copy the number in the cell to the right to the clipboard. For example:
If Sheet1 A1 = 120200 1885 I want to find 120200 1885 on Sheet2 and copy 42.43 to the clipboard
Or if it's 130133 1887 I want "x" copied to the clipboard and so on.
I think I want to have a macro "Find" the cell and copy the one next to it, but I don't know the syntax to do that. The macro recorder only takes me part way.
I can't figure out how to make a VLOOKUP formula work, as there's way more than 65,000 lines to make a lookup table out of the data.
Need to pull data from Sheet4 to sheet1 by Sales Person based on a validation list cell on sheet1.
Each Sales person has a different number of accounts listed on Sheet4. The data is setup like this (my apologies for not knowing how to copy and paste the data)
Will Use Jane Doe and John Smith As examples-
A1, Jane Doe, Customer Name, Data, Data, Data, etc.
A2, Jane Doe, Customer Name, Data, Data, Data, etc.
A3, John Smith, Customer Name, Data, Data, Data, etc.
So Jane Doe has 2 customers total, and John Smith has 1 customer.
I am dealing with a total of 300+ Sales People and over 4,000 customers, all with a different number of customers per sales person.
How in the world can I write a code that will pull all of Jane Doe's customers when she is chosen from the validation list, and paste those customers and their coinciding data where I need it to paste?
I have the validation list working, so all I need at this point is help with the copy/paste code.
I’m using these two codes to find a variable thru a source range. Everything looks to be working well, but as soon the macro tries to copy the returned range I got the following message. Run-time error ‘1004’: Copy method of Range class failed
However, when I press the end button in the error window, the returned range is copied into the target range. Does anybody know how to avoid the error message? Also, is there any way to pass the returned range to an array?
Note:
The source range is 40,000 rows by 14 columns
The returned range is 163 rows by 14 columns.
Sub SearchRangeOne()
Dim SourceRange As Range
Dim TargetRange As Range
Application. ScreenUpdating = False
Set SourceRange = Worksheets("Actual").Range("Actual_Key")
If Not Find_Range(Range("A1").Value, SourceRange, xlValues, xlPart) Is Nothing Then.............
I am trying to remove the last 6 character from a variable. I worked out how to do it using formula's in XL, but want to move this in to VBA. Currently I have this
Mid(ActiveSheet. Name, 1, Find(" Intrdy", LookIn:=ActiveSheet.Name))
however it does not like the find function. Does it exist? am I using it correctly?
I have 2 worksheets, one called Summary and the other called LNB. Column A in both worksheets contain account numbers.
I am trying to tell excell to look at the LNB worksheet and find the account number that is on the summary worksheet. If the account number is found, then tell me the row, on the Summary worksheet, that the account was found.
The function returns "Empty" even though I know the accounts do exist on both sheets and I dont know why.
Here is the code ....
I am attempting to use the Find and Replace code you assisted with me into another project, But I am missing something. I keep getting a Variable not define error when I go to search for a CMM # in the add a referral form.
Highlight in yellow is the code ...
I have never used VBA in word before, so I am assuming I am making it more complicated than it needs to be. I have a macro that stores 20 excel values as variables, then opens up a word document. I want to replace values in word with my values in excel. I keep getting an error with the replace part. I do not want to use bookmarks or mail merge. MSWord is a reference in excel VBA.
Code that stores excel variables (Example: Var1=Data1 and Var2=Data2)...
'Opening up the correct word document
Dim WdApp As Object, WdDoc As Object
Set WdApp = CreateObject("Word.Application")
WdApp.documents.Open ThisWorkbook.Path & "" & Range("D1").Value & ".doc"
WdApp.Visible = True
[Code] ..........
I'm trying to work on a macro that will copy two cell ranges (name of current month and prvious month) from one location, store it as a variable and use that variable to find replace similar text string in another tab. Below is my code which is not changing the values in another tab...
Dim OldMonth As String
Dim NewMonth As String
Sheets("X1").Select
[Code]....
I am having trouble using the find function. I need to store a date as a variable and then find this date on another worksheet. The date is in the following format:
dd-mmm-yy
This is what I currently have which gives me a run time error 91:
Code:
Dim DateSearch As Date
DateSearch = Range("C3").Value
Cells.Find(What:=DateSearch, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
I am still a novice in you standards, but have run into a problem and hoping you all will have some insight for me.
I have a workbook that I am parsing data from the first sheet and putting the data onto the second sheet. Before I place the values in I want to format the cells with boarders, colors, alignment, and in some cases validation (but I can worry about the validation later).
Currently what I am doing is using a 3rd page that has a group of cells that have the formats I want in place before I start. The code will then parse the data and when it finds the data I need go to sheet 3 and grab a range of cells and paste those cells to sheet 2 and then write the data over those cells. This allows me to format the document as I create it.
The problem is that I am going through 25k of lines and on average this function is running 40+ minutes. If I run the same script with out the formatting it only takes at most 2 minutes.
So on to the question.
Is there a way that I can start of my script by grabbing all the format information before I parse the data and save it as a variable? Then instead of doing a copy of the format it would just apply the formatting that is saved already. I would think this would be much faster of a process.
I have a database application which appends an "A" to the sequence number each time an entry is amended and then posts it as a new row in the database. This means there can be multiple entries with the same number but with different amount of "A"'s afterwards.
e.g.
Cell A6 contains seq no 1
Cell A7 contains seq no 2 - Seq no 1 is subsequently amended so...
Cell A8 contains seq no 1A - 1A is subsequently amended so...
Cell A9 contains seq no 1AA - and so on and so forth..........
What i am trying to achieve is a formula which will look at the record number which is required (i.e. 1) and will search for record 1 with the most number of "A"'s appended. This way the user will only be amending the most up to date record.
The formula i have tried (but doesn't work) is:
=INDEX(A6:A65536,MATCH(B2&MAX(LEN(A6:A65536)),A6:A65536,1),0)
(B2 is the record the user wants to amend)
I am trying to create a macro (please look the attached excel what I have done), I have already crwated a macro that after 5 seconds is gonna change the background color of the of the cell en function of another cell.
That means if F3:F4 change the background color F8:is going to change the backgorung color also, every 5 seconds. The macro I wrote is also include in the excel attached file.
Now this is my problem... I have a variable cell that is give for D6 which could be A,B,C,D,E,F (Range F2:K2).
If the variable cell D6 is A the background color of F8:F9 should be the background color F3:F4 .
If the variable cell D6 is B the background color of F8:F9 should be the background color G3:G4 .
If the variable cell D6 is C the background color of F8:F9 should be the background color H3:H4 ......and etcetera.
If Not stfound Is Nothing Then 'if value is found then do this
is causing me a run time error 424 when I try and run my code "Object required". Entire code is pasted below...
Option Explicit ....
I have a spreadsheet with a couple of hundred rows on each tab that looks like this: A1: #1 PENROSE TIJUANA MAMA PCH 2620039190 665794 12.00 CT 1 Front 1 1 1. The only constant is the 10 digit number followed by the 6 digit number in the middle and I want to use it to parse the text string. I want the output to be everything prior to the 10 digit number in A1, the 10 digit number in B1, the 6 digit number in c1 and everything else in D1 and so on through the rows.
View 4 Replies View RelatedHow do I use VBA to send the value of a cell, for example, cell J77 to the variable "mastervalue1"?
I have a spreadsheet that has a column with dates ( in the format "mmm-yy") and next to it a column that has values. I want to pass the value of the cell that is next to the date cell that contains today's month to a variable in VBA. Auto Merged Post;here's an example of my spreadsheet
I need to store a known index, unknown value in a variable so I can increase the value and use it in a database. It is used as a version number for a part and the versions go like: "00" -> "AA" -> "AB" -> .... -> "AZ" -> "BA"... etc.
VB:
If tool.Worksheets("TRB Database").Cells(A, "R").Value <>
ThisWorkbook.Worksheets("Design Calculator, Q").Cells(7, "C").Value Or
tool.Worksheets("TRB Database").Cells(A, "AA").Value <>
ThisWorkbook.Worksheets("Design Calculator, Q").Cells(5, "K").Value Or tool.Worksheets("TRB Database")
[Code] ....
That is a part of the increase and when I try to increase "AA" by 1 it goes to "B" and not "AB".
VB: tool.Worksheets("TRB Database").Cells(row1, "D").Value = Chr(Asc(tool.Worksheets("TRB Database").Cells(A, "D").Value) + 1)
This is where I increase the value.
I have a monthly report. Worksheets for each month, each row is a type of fruit (column A), and the number sold (column B). A new worksheet is added each month with the information. I also have a Summary worksheet - running total of all months: Type of Fruit (column A), Number sold (column B), and Total of all fruits - number sold. I would like a formula for the Summary worksheet - to match that fruit (column A) to any of the other worksheets - matching the fruit (column A), and bring back the number sold (column B). (note some apples are Fuji and some are Honey crisp - those would be totaled together)
ex:
Tab = Jan 14
Fuji apples3
Bananas2
grapes9
TOTAL14
[Code]....
I am acquiring multiple spreadsheets that do not always match row number, due to additional information on some sheets. By this I mean that the information may be in row 31 on on sheet and row 39 on another, the column location is the same each time. I have been trying Vlookups, indexing and matching plus combination formulas - with no luck. How to get the information I need with a moving cell reference?
I can provide a small copy of a workbook, if needed.
I have a worksheet named "ABC". In row 4 of this worksheet, each cell from G to BG is numbered from 1 onwards and each cell has a unique number. I would like to have a macro ask the user through a pop-up question box which column data should be calculated in. For example, if the user types "1" in the question box, the macro will go to column G which has "1" in cell G4 and will select G5 the cell just below the column the user defined and calculate the formula.
View 6 Replies View RelatedMy data is set out in columns, where alternate columns provide day numbers for given years (we can call these type 1 columns), with adjacent columns containing values which correspond to those type 1 column day numbers (we can call these type 2 columns). There are about a hundred columns in total (50 of each type). I would like to get excel to return the three largest numbers within each type 2 column, but I want to exclude data within the type 2 column above the point which is adjacent to a specific (varying) day number in the type 1 column. The location of this point varies for all the type 1 columns, according to a third row of numbers (the look up start point), which are currently listed below the dataset in every type 1 column. So, for the type 1 column "year 1", I would want Excel to ignore the values 0 and 1, which are listed next to day numbers 78 and 79, and begin looking for the three largest values down the column starting from the value which is adjacent to 81 (which is a 2). In type 1 column "year 2", excel would start looking for the largest values from the cell adjacent to 78, so it would ignore the 18 at the top of the column,and would return 2 and 12. And so on.
Year1
Value
Year2
Value
Year3
[Code]...
look up startpoint
81
78
62
83