Naming Pasted Range
Mar 26, 2008After pasting a Range and while the Range is still selected, I would like to Name it. May I have some assistance with the proper statement?
View 9 RepliesAfter pasting a Range and while the Range is still selected, I would like to Name it. May I have some assistance with the proper statement?
View 9 RepliesI have been struggling for a while to copy data from one worksheet to another and reset the target range.
The copy bit is cool, the range resetting bit is not. I have tried various methods, but none seem to work.
For example, the below code generates an error: "Compile error: Argument not optional"
I have stuck the particular command button script below to let you see what I am trying to do:
Private Sub cmbFilter_Click()
Dim sCriteria As String
On Error Resume Next
What is the proper syntax for working with a Range with to name it after the PasteSpecial command? The Selection approach I am trying here does not seem to work unless I am currently within the same workbook.
[URL]
VB:
Sub Create_Dashboards()
With Sheets("Revenue Model") 'Strat Plan Revenue
.Range("J2:S9").CopyPicture
.Range("A42").PasteSpecial
Selection.Formula = Range("J2:s9").Address
Selection.Name = "Strat Plan"
'more code here
End With
End Sub
I have this code going for a sheet i've been working on, but thers only one thing I can't figure out how to do.
I want it to take the text that was entered in the "Grid Date" input box and stick it in the bottom 10 cells (plus one space). IE - if A14 is the last used cell, paste it into A16 through A26.
I have a data range in sheet1 that I would like to copy into a new sheet. to copy I have used the following code
Worksheets("input").Range("input").Copy Destination:=Worksheets("temp1").Range("B12")
I would like to name the data that has been copied into sheet"temp1"
Below is code I have attempted. I am learning VBA and have gathered this code from the internet and this forum. I have data that is in columns B to E and from row 7 down. I want this VBA code to run when data is copied/pasted in these cells. Where the last values stop will vary so I just want to be sure this code is executed after all the data is pasted in these cells. The data will be pasted at one time. When the user removes the data from these cells, I do not want the code to run.
Private Sub Worksheet_Change(ByVal Target As Range)
'Do nothing if less than four cells are changed or content deleted
If Target.Cells.Count < 4 Or IsEmpty(Target) Then Exit Sub
[Code].....
I want to use the range in this code that works fine in one work book from sheet to sheet...
But i need it to run across 2 workbooks that are both open at the same time... The data its bringing back will be in a seperate workbook.
Sub zzzz()
Sheets("Sheet2").Select
Range("A3:M16").ClearContents
c = 3 'Paste Range Return Test
x = Worksheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Row 'data source
For a = 1 To x
If Worksheets("sheet1").Cells(a, 3) = Worksheets("sheet2").Range("a1") Then
For b = 1 To 20
Cells(c, b) = Worksheets("sheet1").Cells(a, b)
Next b
c = c + 1
End If
Next a
'Range("C3:C15,F3:F15,I3:I15").Select
'Selection.Delete Shift:=xlToLeft
Range("A1").Select
End Sub
A userform listbox places names in a column in Sheet2, starting with cell E1 and subsequent transfers from the listbox (which is multiselect) going to F1, G1 etc. There will be between 6 and 15 names in each case.
A seperate textbox is used to assign a number to each multiselection, this number is added to "Div" and placed in row 22 of the column to which the multiselection is transfered.
The text in this cell is used for other things later but I also want to use it to Name the range to which it refers. This name is then immediately used to populate another listbox in the userform, and will be used repeatedly later on in the project.
Here is the relavant snip of code that I have been trying to get to work but I get 'object required' for the ActiveWorkbook.Names.Add.......... line. I did manage to get rid of that once (can't recall how!!) but then the ListBox2,RowSource gave an error.
Set DvNm = Sheet2.Range("IV1").End(xlToLeft).Offset(21, 0)
Set Rngc = Sheet2.Range("IV1").End(xlToLeft)
Set Rngp = Sheet2.Range("D65536").End(xlUp).Offset(1, 0)
DvNm.Value = "Div" & TextBox1.Value
Range(Rngc, Rngc.Offset(15, 0)).Copy
Rngp.PasteSpecial (xlPasteValues)
Application.CutCopyMode = False
ActiveWorkbook.Names.Add Name:=DvMn.Value, RefersToR1C1:="Range(Rngc, Rngc.Offset(15, 0))"
I am making a simple database worksheet for the junior. The first thing we need to re-define the new "size" of the database to do some future calculations. I write some code in workbook open to initiate the name area:
Worksheets("Inventory").Activate
maxrow = 0
maxrow = Range("a7"). CurrentRegion.Rows.Count
'Range("A7").Select
Range(Cells(8, "N"), Cells(maxrow, "N")).Name = "tbl_left"
when the junior re-open the workbook after closed, the size of the database
does not growth to a new area even junior add rows of data before close. It seems the currentregion does not work, I've tested it in VBE by press " F8".......
= OFFSET(CustomerInfo!$A$9,0,0, COUNTA(CustomerInfo!A:A),1)
for a "dynamic" range name...i like the concept, but my data validation in a cell that references this "dynamic" range name (with the offset function) doesn't recognize all the values in the range
(when i just range name it, the data validation sees all the names, but not all when i use the offset...)
I am trying to name a selected range in VBA in order to use it in a vlookup table. Code I have so far is as follows:
ActiveSheet.Name = TextN
Range("c9"). CurrentRegion.Select
Call formatting
ActiveWorkbook.Names.Add Name = "formTextN", RefersToR1C1 = Worksheets(TextN) & "!" & "r9c2:r45c13"
The formatting works, but the selection does not get named.
I am having a hard time creating my ultimate gradebook. Right now, I am able to hide a SPECIFIC table on a SPECIFIC worksheet using the following code on a macro button:
VB : Sub HideRow()Range("Table2[#All]").EntireRow.Hidden = True End Sub
The problem is that this sheet will be a template and as a new user inserts a new sheet, I would like to copy and paste this template to each new sheet. Since the Table values change with each new sheet, code wont work on the new tables. How I can name each new sheets table "Class Data", and the macro button to hide will work on each respective sheet?
Is there a way to name a range beginning with a number? It doesn't accept it. Is there a way around this? range name examples: 2DBSUS 3DBSUS
View 2 Replies View RelatedI have a range of data starting in C18, C17 is a label (DivsUsed) the number of rows can range from 1 to a few hundred.
I used the code below to name C18 onwards as a named range with the name DivsUsed and then to use this as a RowSource for a ListBox.
Private Sub UserForm_Initialize()
Dim rangeToName As Range
'Sheet2.Range("C18", Range("C65536").End(xlUp)).Name = "DivsUsed" Tried this too
Set rangeToName = Sheet2.Range("C17", Range("C65536").End(xlUp))
rangeToName.CreateNames Top:=True
ListBox2.RowSource = "DivsUsed"
TextBox2.Value = Sheet2.Range("F2").Value 'This works ok
End Sub
Both tries, and anything else I have tried, give the error " Method 'Range' of object _Worksheet failed".
i'm very new to excel formulas & statistics in general. i only need to calculate averages but am having trouble naming the range in my formulas
in the example below, i want to use the first column to determine the range of data for the mean calculation.... so, I am seeking the average of just the numbers which correspond w/ A only. Similarly, I will then want an average for numbers corresponding to B, and then to C, etc etc...
I am trying to name a Range in VBA with the following Case statement.
Select Case counter
Case "2": Set Wk(numWeeks) = Range("P1:Q136")
ActiveWorkbook.Names.Add Name:="Wk" & numWeeks, RefersTo:=Wk(numWeeks)
I have many more cases and have defined Wk(5) as a Range. What I am really after it is possible to to name the range using something similar to the code above that uses a predefined variable in the naming process.
I have a large file where I want to name about 30 ranges. Initially I had done this using the range addresses and it worked well, but I continue to modify the spreadsheet and add and delete rows, so I need to go back into the code and change the ranges manually. I know there has to be a better way.
What I wanted to try doing was finding some specific text. That text (in all the ranges) is actually one column to the left and 33 rows below where I want to start the named range. Additionally the named range will be a 10 x 33 range. For example, if the data starts in B1, the data to be named will be in B1:K33 and the search title will actually be in A34. Hopefully that's clear...
My original code looked like this:
Code:
ActiveWorkbook.Names.Add Name:="[MyRangeName]", RefersTo:=ActiveSheet.Range("B2:K33")
I was attempting to us the Find function with this code, but I can't seem to figure out how to tell it to look for the text (that would be in A34) and then name the range that would be offset by (-33,1) and then name the entire range.
How to you reference a named range in naming another range? What is the syntax?
I have a dynamic range, and I want a second dynamic range to start in relation to the last cell of the first range.
I need to name a dynamic range of cells. The only constant is the column - H, and the heading "MRC".
MRC column in a table represents an array formula. Unknown is the row where it is going to show up and the number of rows that this array formula will take. I need to name this range (active cells based on the array formula) but do not know what row does it start with and how many rows will it take.
It is not the last table in column H either but there are 2 empty rows before the next table.
Trying something like that...
=========================
Set aCell = Range("H:H").Find(What:="MRC", LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
aCell.Offset(1, 0).Select
========================================
That's how I select the first cell in the range. Not sure how to select the whole range and name it ..
ActiveCell.End(1xDown) ?
Range("B25").Name = "EndMull"
Its fine but if i insert a new row or column then it mucks the whole thing up. Is there away of naming them but if any cells, row or columns are inserted the range will automatically adjust to suit1
macro that will parse data that has been pasted in to Excel from a text document. Once the macro is executed the pasted data will be sent to a separate spreadsheet and parsed horizontally with the data residing in is respective cell.
Here is an example of my data from text:
FIRST: Frank
MIDDLE: N.
LAST: Stien
ADDRESS: APT14
STREET: Halloween
ZIP CODE: 123456
CITY: Scaryville
STATE: Scary Ya
COUNTRY: Transilvania
COMMENT: N/A
Here is an example of my desired results:
A2:Frank, B2:N, C2:Stien, D2:APT14, E2:Halloween, F2:123456, G2:Scaryville, H2:ScaryYa, I2: Transilvania, J2:N/A
The data is always pasted in A2 on the first sheet, and varies somewhat in length but the format is always the same.
I am having trouble figuring out how to paste an Excel Worksheet into Outlook. I am using '07 versions for both. I currently have code that when a button is selected, Outlook opens and has form text that I have entered. I just cant figure out how to get the worksheet pasted into the body of the email after this text. Here is what I have:
View 3 Replies View RelatedI Have several images on Sheet 1, I can copy the needed Images to sheet 2 as needed.
Once the image is pasted to sheet2 how do I assign it to a shape variable so that I can position it as desired.
I do not want to have to use Sheet2.(Range("B2").activate or similar
I'm looking to use
Shp.top = 25
Shp.left =15
Code:
Sub Macro1()
Dim Shp As Shape
Sheet1.Shapes("Picture 1").Copy
Sheet2.Paste
'To set the shape variable to the shape on sheet2
Set Shp = "WHAT GOES HERE"
Shp.Top = 25
Shp.Left = 15
End Sub
I am trying to enter 00:00:00.031, but it is changing it to 00:00.0. Can someone please tell me how to stop it from doing that?
View 9 Replies View RelatedI am starting a data sheet that I will be pasting from the internet into my data sheet daily, the problem I have is that the content data is pasting with blank rows between data and also there is one piece of data that is situated on the row below which i need moving to the end of the main data row, the idea is to have single data rows with no blank rows.
I have attached an example sheet showing the layout it repeats with only the amount of data that changes.
I have colored the data as follows:
Grey= Blank Rows
Yellow= Data Move to end of main row
Green= Unwanted Data
I have a worksheet that you can enter in
Forename, Surname, Area, D.O.B
This has a macro assigned that copies the data and pastes it into another worksheet at the next available row.
Now this works fine, but I want to be able to identify if the data already exists in the other worksheet then prevent it from being pasted and give an error message that the person already exists in the database.
Is this possible?
If I use the code below to retrieve a recordset from SQL Server and the drop it into the activeworkbook, using CopyFromRecordset and a sheet where I have just deleted all the columns - thus leaving a default sheet (I think)....everything works fine
'Drop in field name and data
counter = 1
For Each fld In SQLRS.Fields
Sheet1.Cells(1, counter) = fld.Name
counter = counter + 1
Next
Sheet1.Range("A2").CopyFromRecordset SQLRS
However, if I change it to paste into a brand new work book as in the code below....all the dates are pasted in as Integers...
'Create new book and sheet
Set NewBook = Application.Workbooks.Add
Set NewSheet = NewBook.Worksheets.Add
NewSheet.Name = "Sanofi Renewals"
I've used this same process previously and not had any problems what so ever when dates where pasted....
how to sort data pasted from word into specific columns e.g.
I paste: 1,2,3,4,8 into the ref row, and it poulates as such, leaving out the columns for which there is no corresponding value:
Competency: 1------2--------3-------4------5------6------7------8
Ref: -------WR1----WR1----WR1-----------WR5------------------WR1
I have rxd a pdf file that I need to manipulate I have copied the data into excel and now need it in individual cells:? The data looks like this: 02392950067 19/12/2008 14:33:35 02392950053 Portsmouth 1.9 £0.03. this is:
phone number calling | date called | time called | number called | duration in minutes | cost of call. If you're out there I'd be more than happy to hear from you. the cells to cut the data into will be formatted to take the data in the correct form. 02392950067 19/12/2008 14:33:35 02392950053 Portsmouth 1.9 £0.03
phone number calling | date called | time called | number called | duration in minutes | cost of call.
Whenever I copy and paste dates from the internet I can't get Excel to recognize the info as dates, thus making it impossible to sort by date. It doesn't matter which site I use, I have the problem with all of them.
[URL]
Using any of the links above, how I can paste those dates and get Excel to sort the date?