Question about Computers & Internet

1 Answer

Macro code for copying a range of cells from one Excell w/sheet t

Want to know macro code for copying a range of cells from one Excell 2007 worksheet to another worksheet in the same Excell workbook by simply typing the number allotted in the first column of that particular range of cells of first woksheet into first column of the second worksheet.

Posted by on

  • Royal May 11, 2010

    If I understand yoour request you want to type an entry onto a cell in one worksheet, then activate a macro and this will copy a group of cells from another worksheet in this workbook to this worksheet. The typed entry will have the value of the top left cell being copied from. Does this sound correct?



    If it does then my question is how is one to determine the range of the cells to copy?

×

1 Answer

  • Level 1:

    An expert who has achieved level 1.

  • Contributor
  • 2 Answers

You did not respond to my claification request. Here is some code that might help, it copies a selection of cells going down until an emty cell is found and across until an emty cell is found. This is form an earlier version of office but should comeclose to woring in 2007.

Sub copyrange()
'
' copyrange Macro
' Macro written by Royal 11/22/2008.
'


'save the return values
wksname = ActiveSheet.Name
returncell = ActiveCell.Address
searchfor = ActiveCell.Value

'go to first worksheet and find entered value (note this is a value serach)
Worksheets(1).Activate
findfor = "A1"
On Error Resume Next

findfor = Cells.Find(What:=searchfor, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False).Address
If findfor = "A1" Then
erwks = ActiveSheet.Name
Sheets(wksname).Activate
er = MsgBox("Search item not found on Worksheet" + erwks, , "Search Error")
Exit Sub
Else
findfor.Activate
End If

Cells.FindNext(After:=ActiveCell).Activate

'save this address and start searching for copy area boundaries
begcell = ActiveCell.Address
begcl = ActiveCell.Cells.Column
begri = ActiveCell.Cells.Row
'search amaximum of 1000 rows and 676 columns
endri = begri + 1000
endcl = 26 * 26
maxrow = 0
maxcol = 0

For col = Cells.Column To endcl
If Cells(begri, col) = "" Then
maxcol = col
col = endcl
ri = endri
Else
ri = begri
End If
For ri = ri To (Cells.Row + 1000)
If Cells(ri, col) = "" Then
If ri > maxrow Then
maxrow = ri
End If
ri = endri
End If
Next ri
Next col

maxrow = maxrow - 1
maxcol = maxcol - 1

'copy the selected area
endcell = Cells(maxrow, maxcol).Address
crnge = begcell & ":" & endcell
Range(crnge).Select
Selection.Copy
'go back and paste it in
Sheets(wksname).Activate
Range(returncell).Select
' use this if yo want to paste formulas etc.
'ActiveSheet.Paste
' use this code if you want to paste values instead of formulas etc.
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range(returncell).Select

Posted on Nov 29, 2008

1 Suggested Answer

6ya6ya
  • 2 Answers

SOURCE: I have freestanding Series 8 dishwasher. Lately during the filling cycle water hammer is occurring. How can this be resolved

Hi,
a 6ya expert can help you resolve that issue over the phone in a minute or two.
best thing about this new service is that you are never placed on hold and get to talk to real repairmen in the US.
the service is completely free and covers almost anything you can think of (from cars to computers, handyman, and even drones).
click here to download the app (for users in the US for now) and get all the help you need.
goodluck!

Posted on Jan 02, 2017

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

2 Answers

What is exel sheet extension in office 2010 ?


Excel Workbook

.xlsx

The default Excel file format. Cannot store VBA macro code or Microsoft Excel 4.0 macro sheets (.xlm files in Excel 4.0).

Excel Macro-Enabled Workbook

.xlsm

Uses the same basic XML format as the Excel Workbook, but can store VBA macro code. Users saving an Excel workbook that has VBA code or Excel 4.0 macro sheets (.xlm files in Excel 4.0) are prompted to use this file format.

Excel Template

.xltx

The default file format for an Excel template. Cannot store VBA macro code or Excel 4.0 macro sheets (.xlm files in Excel 4.0).

Excel Macro-Enabled Template

.xltm

Can contain a VBAProject part or Excel 4.0 macro sheets (.xlm files in Excel 4.0). Workbooks created from this template inherit the VBAProject part or Excel 4.0 macro sheets that exist in the template.

Excel Add-In

.xlam

A supplemental program that runs additional code. Excel add-ins use the Open XML file format to store data, and they support using VBA projects and Excel 4.0 macro sheets.

Feb 21, 2011 | Computers & Internet

2 Answers

I want to know about macros


you can find more information about macro and usage of macro from
Automate computer tasks easily with macro software

Oct 29, 2010 | Computers & Internet

1 Answer

How to create macro button in microsoft excel 2007 because


well follow the steps below to get your job done:

To create an option button in Microsoft Office Excel 2007, make sure that you add Option Button (form control) to the Quick Access Toolbar. To do this, follow these steps:
  1. Click the Microsoft Office Button, and then click Excel Options.
  2. Click the Customize category, select All Commands in the Choose commands from list, select Option Button (form control), and then click OK.
To create an option button and to assign a macro to it, follow these steps:
  1. In Excel 2003 and in earlier versions of Excel, click Option Button on the Forms toolbar, and then draw the outline of the button on the sheet.

    In Excel 2007, click Option Button (form control) on the Quick Access Toolbar, and then draw the outline of the button on the sheet.
  2. Select any cell in the worksheet.
  3. In versions of Excel that are for Microsoft Windows, right-click the option button, and then click Assign Macro.

    In versions of Excel that are for Macintosh, press COMMAND while you click or press CTRL while you click, depending on your operating system version. Then, click Assign Macro.
  4. In the Assign Macro dialog box, click the name of the macro that you want to assign to the option button, and then click OK.
When you click the option button, the macro will run.


good luck ...:-)

Apr 08, 2010 | Microsoft Office Excel 2007

2 Answers

I Have list of numbers in coloumn in a sheet & i want its uniqe record in another sheet how it to do?


You can use some add in for Excell, can be found much of them on internet. Or follow this instruction: http://www.cpearson.com/excel/Duplicates.aspx for any brainstorming :)

Mar 11, 2009 | Microsoft Computers & Internet

1 Answer

Closing Worksheet on executing Hyperlink command


You could do this by creating a close button with the worksheet- Do this via insertin ga prompt in Macro.

Dec 20, 2008 | Microsoft Computers & Internet

1 Answer

Macro


Hi alwinkumar

You can set a default value in most form items under the properties of that item. Look for "value". You can also do this in code, by setting up a sub routine to set/reset the values on your form. Then just run the sub routine before you open or enter the form.

Private Sub resetForm()

'formname.itemname = value
UserForm1.Label1 = "Hello World"

End Sub

For the second one you have a couple of options, you can find the bottom on the data and store the row index in a variable, use a loop to find the next empty cell in a row, and store the value or you can use the current region method to select all the cells with data continously touching the selected range. Example below

numberOfRows = Sheet1.Range("A1").CurrentRegion.Rows.Count

Jul 16, 2008 | Microsoft Office Professional 2007 Full...

2 Answers

Attendance sheet in Excel


Hi KDina,

If you need me to work on this project for you please contact me at hdbas8@gmail.com

May 17, 2008 | Excel (SS8SATAS5128400R)

1 Answer

Macro


Sure,

Private Sub Workbook_Open()
Application.OnTime TimeValue("15:00:00"), "MyMacro"
End Sub

This will run the Procedure MyMacro at 15:00 each day.

Mar 19, 2008 | Computers & Internet

Not finding what you are looking for?
Computers & Internet Logo

Related Topics:

432 people viewed this question

Ask a Question

Usually answered in minutes!

Top Computers & Internet Experts

Les Dickinson
Les Dickinson

Level 3 Expert

18385 Answers

kakima

Level 3 Expert

102366 Answers

David Payne
David Payne

Level 3 Expert

14161 Answers

Are you a Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...