Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Sort Paste Macro

Status
Not open for further replies.

rfvedcwsxqaz

Programmer
Sep 6, 2007
9
US
This is Macro is for selecting sorting and pasting values.

I was able to get the values from any column of the selection area to populate other cells, but I cant populate the correct number of cells without giving the exact range of the destination.

Among other things, I tried to use offset functions and I tried to rearrange the position of the var declaration.

Thanks for your help.

Code:
Public Sub copysort1()
Dim cell As Range
Dim rng As Range
Dim var1, var2, var3, var4, var5 As Variant
Set rng = Selection
With rng
var1 = .Columns("B")
'.Columns("B").Copy Sheets(2).Range("a1")
'- this works, but I cant use it, its not a variable
End With
'implementation
Range("h1") = var1
Range("g1:g11") = var1
End Sub
 
Hello there,

Why don't you try and explain to us the logical process you are trying to take. As it stands now, with the code you posted it does not make any sense at all and will fail on you. Describe your data structure and process(es) in their entirety.

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
This is an experiment I created for myself so that I could figure out a method of passing data by selection, instead of coding the fixed location of the data source.

Copy the code I wrote and then fill a 5x5 set of cells with numbers. Then highlight the values and activate the macro.

I was able to work with the selection property and I could pass values, but I could not separate the columns of data from one another. I need to have the possibility to pick columns 1,2, and 5 and copy the columns so that the 5th column is now in the same place column 3 once occupied.

I included a line of code that worked for moving a column of data, but the code is for a fixed location.

Having the data pass through the variables will also let me call the variables later in my code at the appropriate time.
The other program involves making a new sheet and the focus will change from the old book to the new book.

The program I made is an office function that by the selection process of the user and clicking a button, they can create a new woorkbook.
The new workbook is named from cells in the old workbook, the form, and the date function.
The workbook has one sheet that is formatted and created programmability, and the selected data is transferred and sorted into the right places on the new spreadsheet.

Things to do to finish that project:
1. get code that sorts data and puts it in a new place
2. a save as dialog that works correctly

Thanks for reading this all, let me know if you can help!
Im stuck!
 
I need to have the possibility to pick columns 1,2, and 5 and copy the columns so that the 5th column is now in the same place column 3 once occupied

To do this, you would need to do the copy 1 column at a time

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 




Instead of copy paste, consider a horizontal sort, inserting a ROW to order the columns, sort, then delete the row.

Skip,

[glasses] When a group touring the Crest Toothpaste factory got caught in a large cooler, headlines read...
Tooth Company Freeze a Crowd! and
Many are Cold, but Few are Frozen![tongue]
 
Within the 'With' Statement I was able to distinguish the columns from one another...
I was trying to get one column to copy at a time within the with statement, but I was only getting the first row of each column.

Skip, can you show me how a horizontal sort works?
 



Look at Sort Oprions.

Skip,

[glasses] When a group touring the Crest Toothpaste factory got caught in a large cooler, headlines read...
Tooth Company Freeze a Crowd! and
Many are Cold, but Few are Frozen![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top