Previous in Forum: Excel Formula   Next in Forum: For semi finished stock maintain software
Close
Close
Close
10 comments
Rate Comments: Nested
Active Contributor

Join Date: Oct 2008
Location: Longview, TX
Posts: 14
Good Answers: 1

Excel macro Commands

12/02/2008 8:23 PM

I download many data points each day and have a macro to distribute these points to individual spreadsheets. The macro opens the individual spreadsheet, accesses the data point, copies to the CURRENT CURSOR LOCATION in the spreadsheet, saves the spreadsheet, and closes it. The macro then indexes to the next value, opens the new spreadsheet, etc. I would like to have the macro move the cursor down one cell to the next unoccupied cell below the just input data point before saving and closing the spreadsheet. Any ideas?

__________________
You can't manage what you can't measure.
Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.

Good Answers:

These comments received enough positive votes to make them "good answers".

"Almost" Good Answers:

Check out these comments that don't yet have enough votes to be "official" good answers and, if you agree with them, vote them!
Anonymous Poster
#1

Re: Excel macro Commands

12/02/2008 11:13 PM

Can you not just simply use the "Record Macro" function?

Register to Reply
Active Contributor

Join Date: Oct 2008
Location: Longview, TX
Posts: 14
Good Answers: 1
#2
In reply to #1

Re: Excel macro Commands

12/03/2008 9:07 AM

Using the record macro function is how I created the distribution macro in the first place. But trying to place the cursor refers to a specific cell, not just the next unoccupied cell. I think I need a logic command.

__________________
You can't manage what you can't measure.
Register to Reply
Participant

Join Date: Dec 2008
Posts: 1
#3
In reply to #2

Re: Excel macro Commands

12/03/2008 11:57 PM

How about trying something like:

Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select

First command should take till the end of the data and next one offsets by one row.

Register to Reply Score 1 for Good Answer
2
Commentator

Join Date: Oct 2006
Location: East Coast, US
Posts: 94
Good Answers: 3
#4
In reply to #3

Re: Excel macro Commands

12/04/2008 1:25 AM

Good idea, but I think it would take the activecell to the end of empty spaces if he's already at the end of a 'list'. Or to the beginning of the next list if applicable.

I think this would work globally.

Dim x As Variant
Dim y As Variant
x = ActiveCell.Row
y = ActiveCell.Column
Cells(x + 1, y).Activate

Place the Dim statements at the top of the macro

* AFTER the Sub or Function statement *

i.e. Sub MyMacro1

Dim x As Variant

Dim y As Variant

Place the other 3 lines at the end of the macro BUT

* BEFORE the End Sub statement AND BEFORE any statements that would close the worksheet *

* Make sure these 3 lines are AFTER the normal lines of code, otherwise it may adversely affect the operation of the macro *

i.e. Sub MyMacro1

Dim x As Variant

Dim y As Variant

*Current Lines Of Code*

x = ActiveCell.Row
y = ActiveCell.Column
Cells(x + 1, y).Activate

Workbook.Save

Application.Quit

End Sub

Register to Reply Good Answer (Score 2)
Power-User
United States - Member - New Member Engineering Fields - Chemical Engineering - New Member

Join Date: Apr 2007
Location: Austin, TX
Posts: 367
Good Answers: 10
#5
In reply to #4

Re: Excel macro Commands

12/04/2008 8:28 AM

I like that answer, it is better than what I was going to suggest which was keep a counter variable running in the spreadsheet that gets updated by the number of new datapoints each time it runs.

__________________
Money doesn't talk, it screams in your face.
Register to Reply
Active Contributor

Join Date: Oct 2008
Location: Longview, TX
Posts: 14
Good Answers: 1
#7
In reply to #4

Re: Excel macro Commands

12/04/2008 11:33 AM

I'll try this method and let you know how it works. Seems like a lot of code just to move the cursor. It's going to make the macro very long. I've already chopped it into two pieces just to make it run.

__________________
You can't manage what you can't measure.
Register to Reply
Commentator

Join Date: Oct 2006
Location: East Coast, US
Posts: 94
Good Answers: 3
#8
In reply to #7

Re: Excel macro Commands

12/04/2008 7:14 PM

It can be shortened as follows:

Cells(ActiveCell.Row + 1, ActiveCell.Column).Activate

I only used variables only to minimize the chance of error. I'm not in any way a master programmer, but I've been around it enough to accomplish what I need.

I've found that sometimes when you call the value of an object directly, if gives an error. But when it is stored in another variable first, everything is fine. Something to do with the Object-Oriented Programming, I think.

So, if you want, remove the 2 Dim statements & replace the 3 prior lines of code with the one listed above.

How big is this macro? Sounds pretty substantial for 5 lines of code to make it "very long"...

You might be able to simplify it with code not generated by excel. Such as a Do...Loop Event

Register to Reply Score 1 for Good Answer
Active Contributor

Join Date: Oct 2008
Location: Longview, TX
Posts: 14
Good Answers: 1
#10
In reply to #8

Re: Excel macro Commands

12/04/2008 8:50 PM

Thank you very much for your interest and your input. The other suggestion worked as hoped so I'm using it now. I think this exchange has piqued my interest enough to make me want to get a book on Visual Basic and try to get more competent. Thanks again for your input.

__________________
You can't manage what you can't measure.
Register to Reply
Active Contributor

Join Date: Oct 2008
Location: Longview, TX
Posts: 14
Good Answers: 1
#6
In reply to #3

Re: Excel macro Commands

12/04/2008 11:30 AM

Thanks, I'll try the second line of code because the cursor already resides in the last occupied cell. I'll try your sugestion first because it's a lot shorter and simpler.

__________________
You can't manage what you can't measure.
Register to Reply
Active Contributor

Join Date: Oct 2008
Location: Longview, TX
Posts: 14
Good Answers: 1
#9
In reply to #3

Re: Excel macro Commands

12/04/2008 8:47 PM

Inserted the second line of code in the macro after every instance of having pasted the value in the first vacant cell, but before saving and closing the worksheet -- works flawlessly! Thanks a lot. Will save me close to an hour of computer time every night.

__________________
You can't manage what you can't measure.
Register to Reply
Register to Reply 10 comments

Good Answers:

These comments received enough positive votes to make them "good answers".

"Almost" Good Answers:

Check out these comments that don't yet have enough votes to be "official" good answers and, if you agree with them, vote them!
Copy to Clipboard

Users who posted comments:

Anonymous Poster (1); ArcticZone (2); betomachine (1); BldgScience (1); Superchemist (5)

Previous in Forum: Excel Formula   Next in Forum: For semi finished stock maintain software

Advertisement